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

Has the approach to verbs in v2 changed? #178

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

Has the approach to verbs in v2 changed? #178

ericnewton76 opened this issue Nov 4, 2017 · 8 comments

Comments

@ericnewton76
Copy link
Member

Issue by ravensorb
Thursday Nov 02, 2017 at 18:53 GMT
Originally opened as gsscoder/commandline#500


I was reviewing the code and the following wiki for vers
https://github.com/gsscoder/commandline/wiki/Latest-Version and I cannot see how they line up.

Ex - the following will not compile

var result = CommandLine.Parser.Default.ParseArguments<AddOptions, UpdateOptions, DeleteOptions(args).MapResult(
    (AddOptions aopts) => {},
    (UpdateOptions upopts) => {},
    (DeleteOptions dopts) => {});

It complains that there is no support for more than one Generic and from looking at the code, I didn't see any overrides or extensions to ParseArguments that supports multiple generics. So I was curious if the approach had changed.

@ericnewton76
Copy link
Member Author

Comment by nemec
Thursday Nov 02, 2017 at 19:08 GMT


Two things:

  1. MapResult has a final delegate parameter that is required to be of type IEnumerable<Error> for any errors.
  2. Each delegate must return a value - they are Func not Action and each value must be the same type. If you quickly add return ""; to each of those it compiles for me.

@ericnewton76
Copy link
Member Author

Comment by ravensorb
Thursday Nov 02, 2017 at 19:16 GMT


Cool So i just tried build 2.1.1-beta and I cannot get the snippet above to compile

error CS0305: Using the generic method 'Parser.ParseArguments<T>(IEnumerable<string>)' requires 1 type arguments

@ericnewton76
Copy link
Member Author

Comment by nemec
Thursday Nov 02, 2017 at 19:20 GMT


Did it mention a file/line number?

@ericnewton76
Copy link
Member Author

Comment by ravensorb
Thursday Nov 02, 2017 at 19:23 GMT


Its in my simple test app and when I look at the object explorer I only see a ParseArguments and not other overloads for more generic args.

@ericnewton76
Copy link
Member Author

Comment by nemec
Thursday Nov 02, 2017 at 19:53 GMT


Sorry I misread and thought you were building the source code of the library. This worked for me on the latest beta:

var result = CommandLine.Parser.Default.ParseArguments<AddOptions, UpdateOptions, DeleteOptions(args).MapResult(
    (AddOptions aopts) => {return ""; },
    (UpdateOptions upopts) => {return ""; },
    (DeleteOptions dopts) => {return ""; },
    (IEnumerable<Error> errs) => {return ""; });

@ericnewton76
Copy link
Member Author

Comment by ravensorb
Thursday Nov 02, 2017 at 20:10 GMT


That helped -- I found the issue :) It appears you must add the using statement

using CommnadLine;

Without that it doesn't find the extension methods or the Error option.

@mhmd-azeez
Copy link

mhmd-azeez commented Aug 2, 2018

@ericnewton76 Wouldn't it be better to mention the need to add using CommnadLine; in the README.md example as well? Or at least write Parser.Default.ParseArguments instead of CommandLine.Parser.Default.ParseArguments to force the programmer to add a using statement.

Because it's not obvious from the example that these are extension methods and can produce frustrating compilation errors.

@heinermann
Copy link

Just ran into this myself, thanks whoever ran into this issue first and shared the fix. 🙏🏻

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

3 participants