commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Has the approach to verbs in v2 changed?

Open ravensorb opened this issue 8 years ago • 6 comments

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.

ravensorb avatar Nov 02 '17 18:11 ravensorb

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.

nemec avatar Nov 02 '17 19:11 nemec

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

ravensorb avatar Nov 02 '17 19:11 ravensorb

Did it mention a file/line number?

nemec avatar Nov 02 '17 19:11 nemec

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

ravensorb avatar Nov 02 '17 19:11 ravensorb

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 ""; });

nemec avatar Nov 02 '17 19:11 nemec

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.

ravensorb avatar Nov 02 '17 20:11 ravensorb