Skip to content

Has the approach to verbs in v2 changed? #500

Open

Description

@ravensorb

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.

Activity

  1. nemec commented on Nov 2, 2017

    @nemec
    Collaborator

    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.
  2. ravensorb commented on Nov 2, 2017

    @ravensorb
    Author

    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
    
  3. nemec commented on Nov 2, 2017

    @nemec
    Collaborator

    Did it mention a file/line number?

  4. ravensorb commented on Nov 2, 2017

    @ravensorb
    Author

    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.

  5. nemec commented on Nov 2, 2017

    @nemec
    Collaborator

    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 ""; });
  6. ravensorb commented on Nov 2, 2017

    @ravensorb
    Author

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions