Skip to content

Announcing CommandLineParser v2.9.0-preview1 #670

@moh-hassan

Description

@moh-hassan
Collaborator

CommandLineParser v2.9.0-preview1 is releases Today (july 24, 2020) with new features.
The package can be downloaded from:

C#: https://www.nuget.org/packages/CommandLineParser/2.9.0-preview1
F#: https://www.nuget.org/packages/CommandLineParser.Fsharp/2.9.0-preview1

What is new in that version, read Changelog

The new features:

  • Multi-instance option support.
    option can be repeated as:
    $ myprog -t value1 -t value2 -t value3
    Configure Parser as:
    var parser= new Parser(with =>{
			with.AllowMultiInstance =true;
		});
  • Move Errors and Value up to the abstract class definition.
    you can extract Options object or Parser Errors from ResultSet:
var result =  parser.ParseArguments<Options>(args);
//extract Options object and errors
Options options= result.Value;
var Errors = result.Errors;
  • Add support for flags enums.
    see wiki
  • Implement verb aliases.
[Verb("copy", aliases: new string[] { "cp", "cpy" }, HelpText = "Copy some stuff")]
        public class CopyVerb
        {
		//....
	}

You can use verb alias:

$ myprg copy -f file.txt		
$ myprg cp -f file.txt		     # use alias
$ myprg cpy -f file.txt		     # use alias
  • New Unparsing Extension method is added: FormatCommandLineArgs to return array of strings.
    see wiki
  • New string extension method SplitArgs to split commandline string with handling double quote with/o keeping the double quote and ignoring the extra spaces in the string.
var myargs="-a xyz --name \"path to file\" -b 123";
string[] args =myargs.SplitArgs();     //return {"-a","xyz","--name","path to file", "-b", "123"}
string[] args =myargs.SplitArgs(true);     //keep quote and return {"-a","xyz","--name","\"path to file\"", "-b", "123"}
  • Allow single dash as a value, now it's allowed: -a - --filename - .

Activity

oolong2

oolong2 commented on Jul 25, 2020

@oolong2

How do flags work? Trying to figure out how to specify multiple values for an enumeration in the command line....

moh-hassan

moh-hassan commented on Jul 25, 2020

@moh-hassan
CollaboratorAuthor

Enum Flags in wiki show how to use multiple values for an enumeration.
Try online demo.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @oolong2@moh-hassan

        Issue actions

          Announcing CommandLineParser v2.9.0-preview1 · Issue #670 · commandlineparser/commandline