4

Using Command Line Parser Library, is there a way to mark a set of say 3 options and make exactly one of the three options required?

So having these options:

[Option("list-plugins", MutuallyExclusiveSet = "Commands")]
public bool ListPLugins { get; set; }

[Option("list-languages", MutuallyExclusiveSet = "Commands")]
public bool ListLanguages { get; set; }

[OptionList('f', "files", ',', MutuallyExclusiveSet = "Commands")]
public IList<string> Files { get; set; }

I'd like the user to only be able to use exactly one at a time.

I.E. valid calls would include calls with exactly one of the options: "MyProgram --files a.txt", "MyProgram --list-languages" and "MyProgram --list-plugins"

while calls without or with multiples of the options: "MyProgram" (this case is my problem), "MyProgram --files a.txt --list-languages" and "MyProgram --list-languages --list-plugins" would be invalid.

PHeiberg
  • 29,411
  • 6
  • 59
  • 81

1 Answers1

2

@PHeiberg, you've put all your options inside the set Commands and this is correct as describe here.

In this way you're telling the parser: hey, let the user pick one of these!.

If you add another option bound to another set:

[Option MutuallyExclusiveSet = "Other"]
public int Offsets { get; set; }

You'll be able to specify it if you want, but the options in Commands set are mutually exclusive.

By actual design, what you ask still not exists (but could be implemented).

Said that, we know that exists a Required property and how it relates?

If you apply a Required = true to one of more option you're (in the actual implementation) contradicting your self and confusing the parser.

Feel free to open an issue.

The actual implementation support verbs command. Please note that verb commands are by design mutually exclusive and you've to peek one (the behaviour you want for options).

Maybe it's not exactly you want, anyway here is described here.

Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158
jay
  • 1,510
  • 2
  • 11
  • 19
  • Thanks. That's how I understood it as well. The verb command construct is not a good match for this situation I think, since there is only one actual command for the program and the two others are variations of help. I have some ideas on how to do it otherwise. I'll open an issue when I get some more time. – PHeiberg Mar 04 '13 at 20:03