dotnet / dotnet/command-line-api
How to know if option is specified if argument has arity ZeroOrOne, and no value is given
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
I need a way to know whether an option has been specified, regardless of whether a value was provided.
An use case would be the git command `git pull --rebase` which can take on an optional value which then modify the rebase command - `false|true|merges|preserve|interactive`
I want to be able to do something like this:
var cmd = new RootCommand
{
new Option("--foo")
{
Argument = new Argument("bar", () => null){
Arity = ArgumentArity.ZeroOrOne,
}
},
new Option("--foo")
};
cmd.Handler = CommandHandler.Create((foo, bar) => {
Console.WriteLine(foo);
Console.WriteLine(bar);
});
cmd.Invoke(new []{"--foo", "baz"}); // prints true baz
cmd.Invoke(new []{"--foo"}); // prints true null
cmd.Invoke(new string[0]); // prints false null
Contributor guide
Assessment
This issue has not been assessed yet.