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

Add ability to skip options with default values for UnParserSettings #541

Closed
MichaelMankiewicz opened this issue Nov 19, 2019 · 6 comments
Closed

Comments

@MichaelMankiewicz
Copy link

MichaelMankiewicz commented Nov 19, 2019

I have many command line parameters with default values in most of them. My app generates .bat file to run itself with parameters which passed to it's main instance. Now Parser.Default.FormatCommandLine makes long string with all parameters, most of which has default values and can be omitted.
I want to be able to set UnParserSettings to skip parameters that has default values when I use it as
FormatCommandLine action's parameter. Is it possible?

@moh-hassan
Copy link
Collaborator

I agree with you to skip the parameters that have default values.
This enhancement may be available in the next release.

@moh-hassan moh-hassan added this to the 2.7 milestone Nov 25, 2019
@moh-hassan
Copy link
Collaborator

I just want to confirm this test case:

class Options
        {
            [Option(Default = 99)] //should be skipped when P1=99
            public  int P1 { get;set;}
            [Option()]
            public  string P2 { get;set;}
            [Option(Default = 88)] //should be skipped when P3=88
            public  int P3 { get;set;}
        }

var options = new Options{P2="xyz" ,P1=99, P3=88}	;

  args should be:  --p2 xyz   

Is it right?

@MichaelMankiewicz
Copy link
Author

Yes, this is exactly what I mean

@moh-hassan
Copy link
Collaborator

@MichaelMankiewicz
The issue is fixed and you can try the nuget Package downloaded from CI server
I appreciate you if you can feedback your test result to merge the PR.

@moh-hassan
Copy link
Collaborator

moh-hassan commented Dec 7, 2019

Example:

  var options = new Options_With_Defaults {P2 = "xyz", P1 = 99, P3 = 88,P4= Shapes.Square }  ;
       var args=     new Parser()
              //Configure Unparser: SkipDefault=true
                .FormatCommandLine(options,x=>x.SkipDefault=true) ;

    class Options_With_Defaults
    {
        [Option(Default = 99)]
        public int P1 { get; set; }
        [Option()]
        public string P2 { get; set; }
        [Option(Default = 88)]
        public int P3 { get; set; }
        [Option(Default = Shapes.Square)]
        public Shapes P4 { get; set; }   //enum option
    }

result:

 args= --p2 xyz

moh-hassan added a commit that referenced this issue Dec 24, 2019
Add ability to skip options with default values for UnParserSettings (#541) and Quote DateTime (#502)
@moh-hassan
Copy link
Collaborator

Fixed in v2.7+, See wiki with online demo

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

No branches or pull requests

2 participants