I want to add a Option<bool>
to the root command but still show the default output when the option is not provided.
RootCommand rootCommand = new RootCommand("My root command");
Option<bool> moviesOption = new("--movies") { Description = "Show available movies" };
rootCommand.Options.Add(moviesOption);
rootCommand.SetAction(parseResult =>
{
if (parseResult.GetValue(moviesOption))
{
foreach (KeyValuePair<int, string> movie in _movies)
WriteLine($"{movie.Key}: {movie.Value}");
}
return 0;
});
return rootCommand.Parse(args).Invoke();
This works when the --movie
and/or -h
is provided. However, when there is no option provided, there is no output at the console at all.
How to still show the default output (which is the same as -h
option output) when no option is provided on the command line?