-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Target a single file for --in
and --out
#322
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution! Can we add a test?
I'm having a hard time figuring out what the best way to do this is. At first I created a Then I thought about doing an entirely new Suite with a check where I still create the tempDirectory and explicitly pass it the file name I wanted to do the check, but then there would be a lot of repetition from stuff that is done in checkSingleFileCli(
"blah", <- name
"index.md", <- file to check to add to what StringFS.fromString(...) returns
"""
|/index.md
|```scala mdoc
|List(1,
| 2, 3, 4) // comment
|```
""".stripMargin,
"""
|/index.md
|```scala
|List(1,
| 2, 3, 4) // comment
|// res0: List[Int] = List(1, 2, 3, 4)
|```
""".stripMargin
) Is that the best way to do this? Or is there a better way to re-utilize what we have? How would you recommend testing this? |
I think we can reuse the same method by adding a new parameter to configure the --in flag. Something like this diff --git a/tests/unit/src/test/scala/tests/cli/BaseCliSuite.scala b/tests/unit/src/test/scala/tests/cli/BaseCliSuite.scala
index fa71e35..8edbeca 100644
--- a/tests/unit/src/test/scala/tests/cli/BaseCliSuite.scala
+++ b/tests/unit/src/test/scala/tests/cli/BaseCliSuite.scala
@@ -19,6 +19,7 @@ abstract class BaseCliSuite extends FunSuite {
expected: String,
extraArgs: Array[String] = Array.empty,
setup: CliFixture => Unit = _ => (),
+ configureInFlag: AbsolutePath => String = _.toString(),
expectedExitCode: Int = 0,
onStdout: String => Unit = _ => ()
): Unit = {
@@ -29,7 +30,7 @@ abstract class BaseCliSuite extends FunSuite {
setup(CliFixture(in.toNIO, out))
val args = Array[String](
"--in",
- in.toString,
+ configureInFlag(in),
"--out",
out.toString,
"--cwd",
|
Also bump the docusaurus version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow --out to also be an individual file (it would require --in to also be a file), which would allow you to for example target --in /extras/readme.template.md --out readme.md
How hard would it be to implement this? I think it would be nice to require --out
to be a valid filename (!Files.isDirectory(out)
) when --in
is a filename. We can perform that validation here
if (Files.exists(in.toNIO)) { |
Do you think it should be required though? I can see if you pass in an individual file to Also, I'll start working on the |
Fair enough, I agree it's not necessary to fail if --out is a directory and --in is a file. |
Cool, that's the way I implemented it. I think this turned out alright! I'll give a couple comments on relevant parts. |
def resolveIn(relpath: RelativePath): AbsolutePath = { | ||
in.resolve(relpath) | ||
} | ||
|
||
def resolveOut(relpath: RelativePath): AbsolutePath = { | ||
out.resolve(relpath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed these since they were unused.
Following up from an offline conversation, I took the liberty to push a commit that makes several changes
|
Previously, mdoc only supported a single --in and --out argument and they both had to be directories. Now, users can specify a list of --in and --out arguments of both files and directories. This change enables nice use-cases like generating a single `readme.md` file in the root directory of a git repo or generating the blog directory of a Docusaurus website. ``` mdoc --in readme.template.md --out readme.md mdoc --in docs --out website/target/docs --in blog --out website/blog ``` This change turned out to be tricky to implement: * the public API for custom modifiers needs to correctly handle the case when --in and --out are files. For example, the Scala.js modifier needs to be able to know where to generate JavaScript files. * we need to report helpful and actionable error messages when validating user input. For example, it's not valid to pair an input directory with an output file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 I think this is ready for merge once CI is green..
@ckipp01 can you take a look to see if everything is still working as expected?
@@ -36,7 +37,8 @@ inThisBuild( | |||
// faster publishLocal: | |||
publishArtifact.in(packageDoc) := "true" == System.getenv("CI"), | |||
publishArtifact.in(packageSrc) := "true" == System.getenv("CI"), | |||
turbo := true | |||
turbo := true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL'd about turbo 🤔
|
||
### Process multiple input directories and files | ||
|
||
Repeat the `--in` and `--out` arguments to process multiple directories and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// on startup for large directories (can take minutes). To prevent | ||
// duplicate notifications, we implement file hashing only for files the | ||
// files we're interested in, see MainOps. | ||
.fileHashing(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This pr introduces the ability to target an individual file with
--in
and also--out
. If an individual file is passed to--out
it also does a check to ensure that--in
is also an individual file.This will allow the use to specify a target without having to worry about globs or anything. It becomes much easier to do things like this like below where
extras
may have various files, but you only want one.or
For the future
Allow--out
to also be an individual file (it would require--in
to also be a file), which would allow you to for example target--in /extras/readme.template.md --out readme.md
.