commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Setting EnableDashDash doesnt seem to work

Open Rand-Random opened this issue 10 years ago • 1 comments

I have the following argument

        -path "C:\foo\bar.jpg"

The following Options class

        public class Options
        {
            [Option('p', "path")]
            public string Path { get; set; }
        }

The following parsing:

        var parser = new Parser(configuration);
        var parseResult = parser.ParseArguments<Options>(e.Args);
        if (!parseResult.Errors.Any())
        {
            var options = parseResult.Value;
            path = new Uri(options.Path);
        }

and here the configuration

    private void configuration(ParserSettings parserSettings)
    {
        parserSettings.CaseSensitive = true;
        parserSettings.EnableDashDash = false;
        parserSettings.IgnoreUnknownArguments = true;
    }

What I get is that in my Options.Path there is only the "ath", instead of the "C:\foo\bar.jpg".

Also I would like to know if there is a way to set the settings for the Default Parser (Singleton)?

Hope you can help me out.

Rand-Random avatar Feb 19 '15 17:02 Rand-Random

I think you misunderstand the purpose of the "EnableDashDash" setting. If you look at the summary for the setting, it forces all values after a -- to be parsed as values. For example:

myapp.exe -- --path "C:\foo\bar.jpg"

Will consist of two positional values "--path" and "C:\foo\bar.jpg" rather than assigning the Path property. This is the same behavior as getopt.

I don't know if you're familiar with getopt, but there are short, single character options set off by a single dash (-p) and long, multicharacter options set off by a double dash (--path). Since short options must be one character only, most getopt-style parsers do not require a space token between the option and value (e.g. -path is equivalent to -p ath or --path ath). If you would like the behavior of PowerShell (no distinction between short and long args) you will probably need a different library.

nemec avatar Feb 19 '15 17:02 nemec