j-maly / CommandLineParser

Command line parser. Declarative arguments support. Rich set of argument types (switches, enums, files, etc...). Mutually exclusive arguments validations.
MIT License
137 stars 30 forks source link

How is ArgumentRequiresOtherArgumentsCertification supposed to work? #48

Closed mhsimkin closed 7 years ago

mhsimkin commented 7 years ago

I have defined my arguments as:

[DistinctGroupsCertification("s", "h,p")]
    [ArgumentRequiresOtherArgumentsCertification("h", "p,c,i,o")]
    internal class CommandLineArguments
    {
         ValueArgument(typeof(string), 's', "serverName", Description = "The friendly name given to the rabbit server connection.")]
        public string ServerName { get; set; }

        [ValueArgument(typeof(string), 'h', "hostName", Description = "The fully qualified host name of the rabbit server.")]
        public string ServerHostName { get; set; }

        [ValueArgument(typeof(int), 'p', "port", Description = "The port that should be used to connect to the rabbit server.", DefaultValue = 5672)]
        public int Port { get; set; }

        [RegexValueArgument('c', "credentials", CredentialsRegEx,
            Description =
                "The username and password that needs to be used to connect to the rabbit server.  This needs to be in the format username|password")]
        public string Credentials { get; set; }

        [ValueArgument(typeof(string), 'v', "virtualHost", Description = "The virtual host on the rabbit server that contains the scribe exchanges.", DefaultValue = "v.pds.ren.scribe")]
        public string ScribeVirtualHost { get; set; }

        [ValueArgument(typeof(string), 'i', "input", Description = "The scribe input exchange.", DefaultValue = "e.pds.tools.scribe.input")]
        public string ScribeInputExchange { get; set; }

        [ValueArgument(typeof(string), 'o', "output", Description = "The scribe output exchange.", DefaultValue = "e.pds.tools.scribe.output")]
        public string ScribeOutputExchange { get; set; }
}

When I run the application and pass the following on the command line:

-h dwerecrq01.hq.bn-corp.com -c renscribeui@Lithium3

I'm getting a CommandLineException thrown that contains this message:

None of these arguments: h can be used together with any of these: p,c,i,o.

I expected that the parse should of passed as I had default values for p, i, and o.

I'm confused as to why I'm getting a message informing me that I can't use p,c,i,o with h.

Thanks

-marc

j-maly commented 7 years ago

Hi, I'll take a look, it is possible that the parser doesn't take the default values into account (which I agree would be expected). Are you using the latest version? I think I've fixed the bug with the wrong error message..

On Aug 9, 2017 7:16 PM, "mhsimkin" notifications@github.com wrote:

I have defined my arguments as:

[DistinctGroupsCertification("s", "h,p")] [ArgumentRequiresOtherArgumentsCertification("h", "p,c,i,o")] internal class CommandLineArguments { ValueArgument(typeof(string), 's', "serverName", Description = "The friendly name given to the rabbit server connection.")] public string ServerName { get; set; }

    [ValueArgument(typeof(string), 'h', "hostName", Description = "The fully qualified host name of the rabbit server.")]
    public string ServerHostName { get; set; }

    [ValueArgument(typeof(int), 'p', "port", Description = "The port that should be used to connect to the rabbit server.", DefaultValue = 5672)]
    public int Port { get; set; }

    [RegexValueArgument('c', "credentials", CredentialsRegEx,
        Description =
            "The username and password that needs to be used to connect to the rabbit server.  This needs to be in the format username|password")]
    public string Credentials { get; set; }

    [ValueArgument(typeof(string), 'v', "virtualHost", Description = "The virtual host on the rabbit server that contains the scribe exchanges.", DefaultValue = "v.pds.ren.scribe")]
    public string ScribeVirtualHost { get; set; }

    [ValueArgument(typeof(string), 'i', "input", Description = "The scribe input exchange.", DefaultValue = "e.pds.tools.scribe.input")]
    public string ScribeInputExchange { get; set; }

    [ValueArgument(typeof(string), 'o', "output", Description = "The scribe output exchange.", DefaultValue = "e.pds.tools.scribe.output")]
    public string ScribeOutputExchange { get; set; }

}

When I run the application and pass the following on the command line:

-h dwerecrq01.hq.bn-corp.com -c renscribeui@Lithium3

I'm getting a CommandLineException thrown that contains this message:

None of these arguments: h can be used together with any of these: p,c,i,o.

I expected that the parse should of passed as I had default values for p, i, and o.

I'm confused as to why I'm getting a message informing me that I can't use p,c,i,o with h.

Thanks

-marc

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/j-maly/CommandLineParser/issues/48, or mute the thread https://github.com/notifications/unsubscribe-auth/ABX8-m3wbEIk7y6-7ujbTeR286sy0PzLks5sWelngaJpZM4OyYXb .

mhsimkin commented 7 years ago

I'm using 3.0.13.

Thanks

-marc

j-maly commented 7 years ago

Should be fixed in 3.0.14, thanks for reporting the issue.