This repository was archived by the owner on Jul 11, 2018. It is now read-only.
  
  
  
            
  
    
      forked from gsscoder/commandline
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 11
Mutually Exclusive Options
        Joshua Shearer edited this page May 30, 2014 
        ·
        7 revisions
      
    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.
;; permitted
$ app --enablejavascript --documentroot ~/var/local/website
;; denied
$ 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.