Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutual exclusive option is not enforced (even when settings.MutuallyExclusive == true) #177

Closed
ericnewton76 opened this issue Nov 4, 2017 · 4 comments

Comments

@ericnewton76
Copy link
Member

Issue by jsmarsch
Wednesday Nov 01, 2017 at 23:15 GMT
Originally opened as gsscoder/commandline#498


I'm working with the stable build (1.9.71). I am trying to set up mutually exclusive options. I have set a mutual exclusion group, and given each option a different string. I also set the MutuallyExclusive option in the parser settings to true.

But, when I call parser.ParseArgumentsStrict(), it always returns true -- even if I specified the mutually exclusive options in the command line.

Is this a known bug?

@ericnewton76
Copy link
Member Author

Comment by nemec
Thursday Nov 02, 2017 at 14:12 GMT


Can you post a sample of the classes/command line you're using? There has been confusion in the past on how the mutually exclusive option works, you may be seeing those issues.

@ericnewton76
Copy link
Member Author

Comment by jsmarsch
Friday Nov 03, 2017 at 00:07 GMT


Sure.
I'm using verbs, so here is some content from one of my suboptions that uses mutual exclusion:

[Option('t', "tableName", HelpText = "Only the named table (schema.tablename) will be enabled for Cdc", MutuallyExclusiveSet = "singleTable")]
public string TableName { get; set; }

[Option('a', "all", MutuallyExclusiveSet = "alltables", HelpText = "All untracked tables will be enabled for cdc, except for tables named in audit.CdcExclusion table.")]
public bool AllTables { get; set; }

The intent is that you cannot specify myApp myVerb -a and myApp myVerb -t in the same execution.

Here's where I set up the parser:


            var commandLineParser = new Parser(s =>
            {
                s.HelpWriter = Console.Error;
                s.IgnoreUnknownArguments = false;
                s.MutuallyExclusive = true; 
            });
            try
            {

                if (!commandLineParser.ParseArgumentsStrict(args, options,
                    (v, i) =>
                    {
                        verb = v;
                        verbInstance = i;
                    }))
                {
                    Environment.Exit(Parser.DefaultExitCodeFail);
                }

@ericnewton76
Copy link
Member Author

Comment by nemec
Friday Nov 03, 2017 at 01:25 GMT


Try adding them both to the same set instead. This SO post implies that the wiki for 1.x is totally wrong and that the new 2.x beta has fixed the issue.

@ericnewton76
Copy link
Member Author

As stated in the excellent answer on the SO article, you just need MutuallyExclusiveSet = "alltables" on the -t,--table option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant