natemcmaster/CommandLineUtils

If the option type is Nullable<T>, return CommandOptionType.SingleOrNoValue if T is CommandOptionType.SingleValue

scott-xu opened this issue · 5 comments

Is your feature request related to a problem? Please describe.
If the option type is Nullable<SomeEnum>, I have to specify CommandOptionType.SingleOrNoValue. Otherwise, the help text would be

  -enumOpt3|--verb3 <VERB3>         nullable enum option desc.
                                    Allowed values are: None, Normal, Extreme.

rather than

  -enumOpt3|--verb3[:<VERB3>]       nullable enum option desc.
                                    Allowed values are: None, Normal, Extreme.

Describe the solution you'd like

  • return CommandOptionType.SingleOrNoValue if T is CommandOptionType.SingleValue
  • improve the parser to support --a value for SingleOrNoValue to keep backwards compatibility

Thanks for writing this up. As long as we can preserve backwards compat, I'm okay accepting a PR to implement these features.

spec about SingleOrNoValue:

Single or no value - a special case of "no value" options where an value may or may not be specified. They can be specified as --name (no value) or --name:value or --name=value. Unlike "single value", these cannot be specified as --name value because the space causes ambiguous usage.

need to find out the exact ambiguous usage and see if we can work out a solution

ambiguous usage

var app  = new CommandLIneApplication();

var optFoo = app.Option("--foo[:name]", CommandOptionType.SingleOrNoValue);
var argBar = app.Argument("bar");

app.OnExecute(() => {
   var foo = optFoo.Value() ?? "none";
   var bar = argBar.Value ?? "none";

   Console.WriteLine($"foo={foo}, bar={bar}");
});

app.Execute("--foo", "HELLO")

What does the user expect here ^ ? Should it print foo=HELLO, bar=none or foo=none, bar=HELLO?

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

Closing due to inactivity.
If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.