gsscoder / commandline

Terse syntax C# command line parser for .NET with F# support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot add numbers as options

siochs opened this issue · comments

Hi,
having

[Option('4', "ip4", Required = true, HelpText = "Target Ipv4")]
public string Ipv4 { get; set; }

Passing the option -4 to the exe makes the string Ipv4 null. Am I doing something wrong?
Thanks

Yes, but this is how I pass the arguments:
MyApp.exe -4 127.0.0.1 -u Username -p Password
--> string Ipv4 = null
MyApp.exe --ip4 127.0.0.1 -u Username -p Password
--> string Ipv4 = "127.0.0.1"
So is this a bug or am I overlooking something?

commented

Hi @siochs the parser is interpreting -4 as a negative integer rather than an option. If you add another property [ValueAttribute(0)]public IEnumerable<string> Remaining { get; set;} to your options, you should see them collected there.

I don't believe it's possible to use integers as short options due to the ambiguity it would introduce. That said, this is clearly a poor user experience - it should warn or error if you have set an invalid short option.

Okay, thanks. I was just confused, I will go with long options --ip4 --ip6 ...