Skip to content

Commit 3f4e100

Browse files
committed
Fix detection of if we can invoke the parsed command or not
1 parent 66caab2 commit 3f4e100

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Cli/dotnet/Extensions/ParseResultExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ public static bool IsTopLevelDotnetCommand(this ParseResult parseResult)
107107
return parseResult.CommandResult.Command.Equals(Parser.RootCommand) && string.IsNullOrEmpty(parseResult.RootSubCommandResult());
108108
}
109109

110-
public static bool CanBeInvoked(this ParseResult parseResult) => parseResult.Action is not null;
110+
public static bool CanBeInvoked(this ParseResult parseResult) =>
111+
parseResult.Action is not null // we have an invokable action (meaning .SetAction was called)
112+
&& IsNotRootCommandWithUnknownArg(parseResult);
113+
114+
public static bool IsNotRootCommandWithUnknownArg(this ParseResult parseResult) =>
115+
parseResult.CommandResult is { Command: var chosenCommand } // we have a command
116+
&& (
117+
chosenCommand != Parser.RootCommand // not the root command, or
118+
// is the root command but isn't an unbound subcommand
119+
|| (chosenCommand == Parser.RootCommand && parseResult.GetValue<string>(Parser.DotnetSubCommand) is null));
111120

112121
public static int HandleMissingCommand(this ParseResult parseResult)
113122
{

0 commit comments

Comments
 (0)