Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Forgind
Copy link
Member

@Forgind Forgind commented Apr 22, 2025

Fixes #45682 using a custom parser

@Copilot Copilot AI review requested due to automatic review settings April 22, 2025 20:37
@Forgind Forgind requested a review from a team as a code owner April 22, 2025 20:37
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Apr 22, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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;

Comment on lines 25 to 29
return new FileInfo(input);
}
else
{
return new FileInfo(input + Path.DirectorySeparatorChar);
Copy link
Preview

Copilot AI Apr 22, 2025

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.

Suggested change
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))
{
Copy link
Member

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;
Copy link
Member

@joeloff joeloff Apr 22, 2025

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?

@Forgind
Copy link
Member Author

Forgind commented Apr 23, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OutputPath (-o) option should ensure trialing slash
2 participants