commandline icon indicating copy to clipboard operation
commandline copied to clipboard

How to configure two optional params with either of them is required?

Open sameerkattel opened this issue 8 years ago • 3 comments

    [Option('a', Required = false)]
    public int a { get; set; }
    [Option('b', Required = false)]
    public int b { get; set; }

But either a or b should be required.

sameerkattel avatar Oct 21 '16 06:10 sameerkattel

Use Mutually Exclusive Options https://github.com/gsscoder/commandline/wiki/Mutually-Exclusive-Options

[Option('a', MutuallyExclusiveSet = "ab")] public int a { get; set; } [Option('b', MutuallyExclusiveSet = "ab"] public int b { get; set; }

skalinkin avatar Nov 04 '16 14:11 skalinkin

@skalinkin Mutually Exclusive sets don't quite work that way. It means you cannot mix options with different "set names" in the same command line. If you made one set "a" and one "b" you couldn't use both at the same time.

@sameerkattel there is no feature matching those requirements in this library today.

nemec avatar Nov 05 '16 06:11 nemec

Would it be sensible to assume that a set of required, mutually exclusive parameters means that exactly one of them must be provided? Like below, where I'd like to accept either -c or -n. Not both. Not none

public class Options
{
    [Option('c', Required = true, SetName = "connection")]
    public string ConnectionString { get; set; }

    [Option('n', Required = true, SetName = "connection")]
    public string ConnectionStringName { get; set; }
}

tpluscode avatar Jan 12 '17 12:01 tpluscode