Question: How to add enum values to helpdisplay
`
static int Main(string[] args)
{
var result = CommandLine.Parser.Default.ParseArguments<ScheduledTaskOptions>(args);
var exitCode = result.MapResult(
options =>
{
return ScheduledTasks.ExecuteTask(options.Task);
},
errors =>
{
var helpText = HelpText.AutoBuild<ScheduledTaskOptions>(result);
helpText.AddEnumValuesToHelpText = true;
_logger.Error(helpText);
return 1;
});
return exitCode;
}
` I am trying to figure out how to display the enum values for my options. I see that HelpText has AddEnumValuesToHelpText, but I have not figured out how to access the autobuild's helptext to set it. There also seems to be various online explanations for different versions of commandline parser in how it works, so I am not sure what features actually work in 2.0.275-beta
I know this is a little bit late, but this can be achieved - you have to re-add the options to the help text after auto-building it (I also cannot work out how to pass config to the AutoBuild method - it seems like an oversight in the API...). The following example assumes you only have Options, not Verbs:
parserResult.WithNotParsed(errors =>
{
// Use custom help text to ensure valid enum values are displayed
var helpText = HelpText.AutoBuild(parserResult);
helpText.AddEnumValuesToHelpText = true;
helpText.AddOptions(parserResult);
Console.Error.Write(helpText);
Environment.Exit(1);
});
I just wish there was a simpler way of specify auto build config... Especially when you have Verb options!