-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add trailing slash for -o Fixes #45682 #48640
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
base: main
Are you sure you want to change the base?
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.
Pull Request Overview
This PR fixes #45682 by updating the -o option parser to ensure that supplied paths have a trailing directory separator.
- Adds a custom parser to the output option
- Appends a trailing slash if it is missing from the provided path
Comments suppressed due to low confidence (1)
src/Cli/Microsoft.TemplateEngine.Cli/Commands/SharedOptions.cs:18
- [nitpick] Consider renaming 'input' to 'inputPath' for improved clarity on the expected data.
var input = argumentResult.Tokens[0]?.Value;
return new FileInfo(input); | ||
} | ||
else | ||
{ | ||
return new FileInfo(input + Path.DirectorySeparatorChar); |
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.
Appending a directory separator and returning a FileInfo could be problematic if the intent is to work with directories; consider using DirectoryInfo instead.
return new FileInfo(input); | |
} | |
else | |
{ | |
return new FileInfo(input + Path.DirectorySeparatorChar); | |
return new DirectoryInfo(input); | |
} | |
else | |
{ | |
return new DirectoryInfo(input + Path.DirectorySeparatorChar); |
Copilot uses AI. Check for mistakes.
return null; | ||
} | ||
else if (Path.EndsInDirectorySeparator(input)) | ||
{ |
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.
Could simplify the else with something like
return new FileInfo(input.TrimEnd(Path.DirectorySeparateChar)+Path.DirectorySeparateChar);
Arity = new ArgumentArity(1, 1), | ||
CustomParser = (ArgumentResult argumentResult) => | ||
{ | ||
var input = argumentResult.Tokens[0]?.Value; |
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.
if the argument is null/empty, shouldn't the parser raise an error or is that checked before hitting the custom parser?
I tried this out in a more meaningful way, and it didn't work as I'd expected. It turns out CustomParsers don't really do anything as far as the output of the parser (??!!) because after it gets the result here, it just throws it away. I'm restarting this PR but with a different change in a different place that should affect commands not connected with the template engine. |
Fixes #45682 using a custom parser