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

Consider alternative syntax #165

Closed
ericnewton76 opened this issue Nov 4, 2017 · 3 comments · Fixed by #634
Closed

Consider alternative syntax #165

ericnewton76 opened this issue Nov 4, 2017 · 3 comments · Fixed by #634

Comments

@ericnewton76
Copy link
Member

Issue by Korporal
Monday Sep 04, 2017 at 15:28 GMT
Originally opened as gsscoder/commandline#476


Hi,

Consider this generic approach, I think it's better for developers, simpler pattern:

static void Main(string[] args) {
  
    var options = CommandLine.Parser.Default.ParseArguments<Options>(args);

    if (options.Available)
       // Values are available here
       if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile);
 
}

just a thought...

@johnjaylward
Copy link
Contributor

Fixed in #634. Example:

var options = CommandLine.Parser.Default.ParseArguments<Options>(args).Value;
if (options != default) {
    // ... do something with your options
}

If you want both the parsed options and the errors, you would do something like this:

var parsed = CommandLine.Parser.Default.ParseArguments<Options>(args);
if (parsed.Value != default) {
    // ... do something with your options
} else {
   // ... do something with Parsed.Errors
}

@johnjaylward
Copy link
Contributor

@Korporal, not sure if you still care, but since you opened this issue initially, I thought I'd tag you that a PR has been created that is similar to your requested syntax

@moh-hassan
Copy link
Collaborator

merged #634 into develop

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

Successfully merging a pull request may close this issue.

3 participants