Add CLI options to control output files#76
Conversation
3cd4a75 to
b666f67
Compare
robrix
left a comment
There was a problem hiding this comment.
Coupla thoughts you can address or not at your option. Nice one 👍🏻
| /// The TSG file to use for stack graph construction | ||
| #[clap(long)] | ||
| #[clap(name = "TSG_PATH")] | ||
| /// The TSG file to use for stack graph construction. | ||
| #[clap(long, value_name = "TSG_PATH")] |
There was a problem hiding this comment.
Could you give me a quick explanation of these annotations? I'm pretty sure I follow what they're doing, but I'm uncertain what they are, if that makes any sense.
There was a problem hiding this comment.
Of course! The clap(...) annotation says this is a command-line argument. long means that it is a long form argument (--XYZ), and because no name is provided, the field name is used. So, the argument is --tsg in this case. You can also use long = "the-tsg" to have a different flag name than field name. The value_name specifies the placeholder that is displayed in the help. So, it'll show something like --tsg TSG_PATH there. If omitted, it derives something from either the type or the field name. I think it was the field name, so it would have been displayed as --tsg TSG.
| output_mode: OutputMode, | ||
| } | ||
|
|
||
| fn validate_path(path: &str) -> Result<PathBuf, String> { |
There was a problem hiding this comment.
Do we intend to support Windows? If so, @patrickt tells me that paths there can contain byte sequences which are generally invalid in strings, which could (I am unsure!) make str the wrong representation for this argument.
Personally I'm in favour of explicitly either treating Windows as unsupported or at least paths like that.
There was a problem hiding this comment.
Thanks for catching that! I have used Path already in most places, so that Windows paths should be supported. I'll change this validator to also work on OsStr and accepts all valid Windows path.
I'll also add something to the help that explains how path specifiers and non-Unicode paths work together.
| total_failure_count += self | ||
| .run_test(test_root, test_path, &mut loader) | ||
| .with_context(|| format!("Error running test {}", test_path.display()))?; |
There was a problem hiding this comment.
I wouldn't mind seeing this extracted into a separate function and called here and below, but it needn't block this PR.
There was a problem hiding this comment.
I'm on the fence, since the factored out function is so small. But, it does improve readability of this code a bit, so I'll do it.
- Accept all valid paths for the tests argument, by changing the validator to accept OsStr. - Add not about path specifications and the handling of non-Unicode paths on Windows.
|
🎉 |
Currently any file output produced by the CLI is put next to the input file it relates to. This PR adds optional arguments to the
--save-*flags to specify the filename. Placeholders can be used that are substituted based on the input path.The default changed to saving the file in the current directory, using the same name as the test file, but excluding directories. For example,
%n.htmlfor visualization.One notable change is that
--save-*take their argument with equals signs instead of using a separate argument. So,--save-graph=%n.htmlinstead of--save-graph %n.html. This is to prevent accidental overwriting of user files when a user issues a command such astree-sitter-stack-graphs test --save-graph first.py second.pywherefirst.pywould unintentionally be interpreted as the path to use for saving the visualization, instead of the first test path.Fixes https://github.com/github/semantic-code/issues/299.
Output of `tree-sitter-stack-graphs test --help`