fclp / fluent-command-line-parser

A simple, strongly typed .NET C# command line parser library using a fluent easy to use interface
Other
530 stars 85 forks source link

Problem with single dashes and longOption #76

Closed avg72 closed 6 years ago

avg72 commented 7 years ago

Parsing an option using a single dash results in errors. See examples below.

This gives a problem: Util.exe -dns "a.b.c" -ip "10.23" -num 23

This works ok: Util.exe -d "a.b.c" -i "10.23" -n 23 Util.exe /dns "a.b.c" /ip "1.2.3.4" /num 23 Util.exe --dns "a.b.c" --ip "1.2.3.4" --num 23

class Options { public bool ShowHelp { get; set; } = false; public string Dns { get; set; } public string Ip { get; set; }

    public int Num { get; set; }

    public static Options ParseArguments(string[] args)
    {
        var parser = new FluentCommandLineParser<Options>();
        parser.Setup<string>(o => o.Dns)
            .As('d',"dns")
            .WithDescription("DNS name");
        parser.Setup(o => o.Ip)
            .As('i',"ip")
           .WithDescription("IP address");
        parser.Setup(o => o.Num)
            .As('n', "num")
            .WithDescription("Number");

        parser.SetupHelp("?", "h", "help")
            .Callback(() => { parser.Object.ShowHelp = true; });

        var result = parser.Parse(args);
        return parser.Object;
    }
}
alsaydi commented 7 years ago

I do not think there is an issue here. The convention is you're using dashes, is to use short names (single letters). In this example Util.exe -dns "a.b.c" -ip "10.23" -num 23, the parse looks at the -dns and interprets that as short where d stands for DNS and n stands for num. So it tries to parse n "a.b.c" as a number.

siywilliams commented 6 years ago

As designed, see https://github.com/fclp/fluent-command-line-parser/issues/24