-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(#45761): Stop forwarding dotnet-watch run arguments to all commands #50558
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: release/10.0.1xx
Are you sure you want to change the base?
fix(#45761): Stop forwarding dotnet-watch run arguments to all commands #50558
Conversation
@dotnet-policy-service agree |
foreach (var child in parseResult.CommandResult.Children) | ||
{ | ||
var optionResult = (OptionResult)child; | ||
|
||
// skip watch options: | ||
if (!watchOptions.Contains(optionResult.Option)) |
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.
Inverting the logic allows a continue to short-circuit the loop.
} | ||
|
||
// skip forwarding run options to other commands. | ||
if (isRunCommand == false && forwardToRunOptions.Contains(optionResult.Option)) |
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.
The meat and potatoes of this PR. Prevents options which only work with the run
command from being passed to other commands.
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.
nit: !isRunCommand
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.
Can we pass command
from the caller and generalize this to if (forwardToSubcommandOptions.Contains(optionResult.Option) && !command.Options.Contains(optionResult.Option))
?
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.
Of course. Give me a bit and I'll get some commits up.
Further Thoughts
This is outside the scope of this fix, but a different PR could go a step further towards generalization by:
nixing forwardToSubcommandOptions
in favor of watchableSubCommandOptions
.
watchableSubCommandOptions
are options that can show up in subcommands that could affect watch
's settings.
For example: run --project
and build [<PROJECT>|<SOLUTION>]
could both set watch
's project path.
@@ -61,6 +61,12 @@ internal sealed class CommandLineOptions | |||
} | |||
}); | |||
|
|||
// Options we need to know about that are passed through to the subcommand: |
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.
add ... if the subcommand supports them
var longProjectOption = new Option<string>("--project") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false }; | ||
var launchProfileOption = new Option<string>("--launch-profile", "-lp") { Hidden = true, Arity = ArgumentArity.ZeroOrOne, AllowMultipleArgumentsPerToken = false }; | ||
var noLaunchProfileOption = new Option<bool>("--no-launch-profile") { Hidden = true, Arity = ArgumentArity.Zero }; | ||
Option[] forwardToRunOptions = |
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'd call this forwardToSubcommandOptions
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.
Nit: You can replace https://github.com/dotnet/sdk/pull/50558/files#diff-6a6fa2fea5af87fda145d79165f529cef772a3227d58494098b7a22511c4aecaR96-R99 with
foreach (var option in forwardToSubcommandOptions)
{
rootCommand.Options.Add(option);
}
Fixes: #45761, #45634, and maybe a regression of #34949.
Context
Watch CLI
Problem
dotnet-watch
has-p
,--project
,--launch-profile
, and--no-launch-profile
as possible arguments. A user can not use these arguments withoutdotnet-watch
forwarding them. These arguments only work with therun
command, and will cause an error if passed to any command butrun
.