-
Notifications
You must be signed in to change notification settings - Fork 292
Mutually Exclusive Options
João Correia edited this page Mar 4, 2017
·
17 revisions
IMPORTANT NOTE: This wiki refers to latest stables, if a beta version is available in github master branch please refer to Latest Version.
You can define options as belonging to a set that is mutually exclusive. Consider an imaginary application that can act as either a web or ftp server, but not both at the same time.
Defining the options class as follows:
class Options
{
[Option(MutuallyExclusiveSet = "web")]
public string DocumentRoot { get; set; }
[Option(MutuallyExclusiveSet = "web")]
public bool EnableJavaScript { get; set; }
[Option(MutuallyExclusiveSet = "ftp")]
public string FtpDirectory { get; set; }
[Option(MutuallyExclusiveSet = "ftp")]
public bool AnonymousLogin { get; set; }
}
and group options in different set. In this way if you combine an ftp option with a web one, parsing will fail.
;; denied
$ app --enablejavascript --documentroot ~/var/local/website
;; permitted
$ app --anonymouslogin --enablejavascript
If you have various sets and each set contains a good number of options, It's better to structure your application with Verb Commands.