Closed mikecole closed 10 months ago
Added ShowHelp, IsEmptyCommand and ShowValues extension methods to InvocationContext. You can now manually show help in command class Run or RunAsync method, for example if a sub-command represents a group and not an action, you can show help. If Run or RunAsync method is missing in command class, then by default it will show help (analyzer warning DMCLI24 is disabled). ShowValues is useful for testing a command, it shows parsed values for current command and its arguments and options.
See below example, root command does not have a handler method so it will always show help and sub-command will show help if command is specified without any arguments or option, and it will show (dump) values if not:
[CliCommand(Description = "A root cli command")]
public class HelpCliCommand
{
[CliOption(Description = "Description for Option1")]
public string Option1 { get; set; } = "DefaultForOption1";
[CliArgument(Description = "Description for Argument1")]
public string Argument1 { get; set; } = "DefaultForArgument1";
[CliCommand(Description = "A sub cli command")]
public class SubCliCommand
{
[CliArgument(Description = "Description for Argument2")]
public string Argument2 { get; set; } = "DefaultForArgument2";
public void Run(InvocationContext context)
{
if (context.IsEmptyCommand())
context.ShowHelp();
else
context.ShowValues();
}
}
}
This works perfectly. Thanks!
Currently the tool supports running the help command like so:
dotnet run -- -?
However, I'd like the command itself to be able to invoke that help text so the following would have the same effect:
dotnet run --
This would mimic the nuget functionality:
dotnet nuget
dotnet nuget -?