Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:59:03+00:00 2026-06-04T16:59:03+00:00

I started to use the CommandLine Parser Library for a tool that will have

  • 0

I started to use the CommandLine Parser Library for a tool that will have both a GUI and a command line execution. Launching the GUI is done via a command line option.

I would therefore like to have required options in case the program is executing in command line mode. Basically, I would want Option 1 and Option 2 to be required if the option “Gui” is not set.

I tried to combine the MutuallyExclusiveSet and Required attributes as shown below, but it does not work as I thought. Did I misunderstand the concept of “MutuallyExclusiveSet” or simply misusing it? Or is it something that the library is not yet supporting?

public class CommandLineOptions : CommandLineOptionsBase
{
    [Option(null, "gui", Required = false, HelpText = "Launch the GUI", MutuallyExclusiveSet = "Gui")]
    public bool Gui { get; set; }

    [Option(null, "opt1", HelpText = "Option 1", MutuallyExclusiveSet = "CommandLine", Required = true)]
    public string Option1 { get; set; }

    [Option(null, "opt2", HelpText = "Option 2", MutuallyExclusiveSet = "CommandLine", Required = true)]
    public string Option2 { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:59:04+00:00Added an answer on June 4, 2026 at 4:59 pm

    As of version 2.0 of CommandLineParser

    The feature as implemented in 1.9.x stable always created confusion, was disabled by default and required the developer to activate it via settings instance.

    From version 2.0.x, where the kernel was completely rewritten, the feature is always active and I’ll show a simple example:

    class Options {
        [Option(SetName = "web")]
        public string WebUrl { get; set; }
        [Option(SetName = "web")]
        public int MaxLinks { get; set; }
    
        [Option(SetName = "ftp")]
        public string FtpUrl { get; set; }
        [Option(SetName = "ftp")]
        public int MaxFiles { get; set; }
    
        [Option]
        public bool Verbose { get; set; }
    }
    

    Set from ftp set are not compatible with the ones from web, --verbose (which doesn’t belong to a set, or better belongs to the default one "" is neutral and can be intermixed at will).

    Valid

    $ app --weburl http://stackoverflow.com --maxlinks 99
    $ app --ftpurl ftp://ftp.myoffice.files.com --maxfiles 1234
    $ app --verbose --weburl http://twitter.com --maxlinks 777
    $ app --ftpurl ftp://ftp.xyz.org --maxfiles 44 --verbose
    $ app --verbose
    

    Invalid:

    $ app --weburl http://stackoverflow.com --maxlinks 99 --ftpurl ftp://ftp.xyz.org
    $ app --ftpurl ftp://ftp.myoffice.files.com --maxfiles 1234 --maxlinks 777
    $ app --verbose --weburl http://twitter.com --maxfiles 44
    $ app --maxfiles 44 --maxlinks 99
    

    Prior to version 2.0

    All the options that belong to a mutually exclusive set are mutually exclusive between them.

    Follow this example:

    class Options {
        [Option("a", null, MutuallyExclusiveSet="zero")] 
        public string OptionA { get; set; }
    
        [Option("b", null, MutuallyExclusiveSet="zero")] 
        public string OptionB { get; set; }
    
        [Option("c", null, MutuallyExclusiveSet="one")] 
        public string OptionC { get; set; }
    
        [Option("d", null, MutuallyExclusiveSet="one")] 
        public string OptionD { get; set; }
    }
    

    With those rules following command lines are valid:

    $ app -a foo -c bar
    $ app -a foo -d bar
    $ app -b foo -c bar
    $ app -b foo -d bar
    

    and these aren’t:

    $ app -a foo -b bar
    $ app -c foo -d bar
    $ app -a foo -b bar -c foo1 -d foo2
    

    As you can see you can’t specify options together that belong to the same set. Remember also that prebuilt singleton (CommandLineParser.Default) don’t work with MutualliyExclusiveSet attribute. You need to dress up a parser by your own:

    if (new CommandLineParser(new CommandLineParserSettings {
        MutuallyExclusive = true,
        CaseSensitive = true,
        HelpWriter = Console.Error}).ParseArguments(args, opts)
    {
        // consume values here
        Console.WriteLine(opts.OptionA);
    }
    

    This is the way mutually exclusive options work in Command Line Parser Library. Anyway to solve your specific problem, I suggest you to define all the options as you would do in a normal console application. Then add the Gui boolean switch. If this option is specified ignore others. If not behave as a normal console app.

    (Another thing: in a subsequent version will be a feature called "subcommands" that will let you manage multiple Options types; this maybe the right case for this upcoming feature.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a command line executable that is run from a C# class library.
I started to use Borland's Turbo C++ a few days ago. I actually have
I started to use vim recently, but I miss the character/line selection methods from
I recently started to use linux, so I have little knowledge about it. At
So I have started to use PHPUnit to test my programs. I have this
I have started to use Alfresco CMS. In my project, there is a new
My Python script (for todo lists) is started from the command line like this:
I've started reading on zend framework and it's use with Doctrine and have implemented
I have homework that should use fork() and wait() system calls: 1) Write two
I have debian lenny command line installation, I am trying to print polish characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.