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

Created on 4 Nov 2017  路  4Comments  路  Source: commandlineparser/commandline

Issue by sameerkattel
_Friday Oct 21, 2016 at 06:33 GMT_
_Originally opened as https://github.com/gsscoder/commandline/issues/364_


    [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.

Most helpful comment

Comment by tpluscode
_Thursday Jan 12, 2017 at 12:15 GMT_


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

``` c#
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; }

}
```

All 4 comments

Comment by skalinkin
_Friday Nov 04, 2016 at 14:05 GMT_


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; }

Comment by nemec
_Saturday Nov 05, 2016 at 06:48 GMT_


@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.

Comment by tpluscode
_Thursday Jan 12, 2017 at 12:15 GMT_


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

``` c#
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; }

}
```

Comment by tpluscode
_Thursday Jan 12, 2017 at 12:15 GMT_

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; }
}

The SetName values would have to be different, but in this example both are "connection". It should be something closer to the following:

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

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

Further, the help-menu will list that both "-c" and "-n" are required to be used, when in reality it is required that exactly one (no more, no less) be used. If there is a way to change this (to control if the help-menu lists "requried" next to a option) please anyone let me know.

Was this page helpful?
0 / 5 - 0 ratings