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

parameter value starts with dash (-) howto ? #110

Open oleksabor opened 4 years ago

oleksabor commented 4 years ago

I'm using the FCLP to get clientid and secret from the command line parameters

It worked fine however I've got secret value generated starting with dash, like -.q=blablablaG0

The problem is that it is not recognised by the FCLP as a parameter value:

public class Config
{
    public string Param { get; set; }
}

[TestFixture]
public class when_parameter_value_start_with_dash
{
    [Test]
    public void parser() 
    {
        var args = new[] { "-p", "-.q=blablablaG0" };

        var sut = new Fclp.FluentCommandLineParser<Config>();
        sut.Setup(_ => _.Param).As('p', "param");
        var res = sut.Parse(args);

        Assert.AreEqual("-.q=blablablaG0", sut.Object.Param);
    }

}

the test fails with

Message: Expected: "-.q=blablablaG0" But was: null

How can I pass parameter value starting with dash ?

I've tried to pass parameter value quoted with double quotes as var args = new[] { "--param", "\"-.q=blablablaG0\"" };

It worked but the parsed value was quoted too:

Expected: "-.q=blablablaG0" But was: ""-.q=blablablaG0""

Should I remove quotes from the Param value manually? Is there any workaround besides this ?