commandline
commandline copied to clipboard
How to configure two optional params with either of them is required?
[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.
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 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.
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; }
}