Giter VIP home page Giter VIP logo

commandlineparser's Introduction

CommandLineParser

Build status

NuGet Badge

CommandLine Parser Library lets you easily define strongly typed command line arguments, allows automatic parsing of command line arguments and mapping the values to properites of your objects.

See Quick Start on how to use the library.

Supports the following Frameworks:

  • NET 2.0
  • NET 3.5
  • NET 4.0
  • NET 4.5
  • NET 4.5.2 and higher
  • NETStandard 1.3 and higher
  • NETStandard 2.0
  • NETStandard 2.1

Motivational Example

Although console applications are more common in UNIX environment, maybe you will one day need to write one for windows too. It is common for command line applications to accept arguments in a time-tested format that can look like this:

Finder.exe -s 3 --distinct directory1 directory2 directory3

You probably get it already - arguments can be short or long, short arguments consist of '-' prefix and a single character, long arguments consist of '--' prefix and a single word.

It may also be handy to support aliases for arguments (long and short name for one argument or even more long or short names for an argument).

For application with one or two arguments, you could probably manage with some switches and ifs, but when there are more and more arguments, you could use a CommandLine Parser library and thus make your code more clean and elegant.

This is the way you define arguments for your application:

CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser();
//switch argument is meant for true/false logic
SwitchArgument showArgument = new SwitchArgument('s', "show", "Set whether show or not", true);
ValueArgument<decimal> version = new ValueArgument<decimal>('v', "version", "Set desired version");
EnumeratedValueArgument<string> color = new EnumeratedValueArgument<string>('c', "color", new string[] { "red", "green", "blue" });

parser.Arguments.Add(showArgument);
parser.Arguments.Add(version);
parser.Arguments.Add(color);

And this is how the arguments are parsed:

try 
{
    parser.ParseCommandLine(args); 
    parser.ShowParsedArguments();
 
    // now you can work with the arguments ... 

    // if (color.Parsed) ... test, whether the argument appeared on the command line
    // {
    //     color.Value ... contains value of the level argument
    // } 
    // if (showArgument.Value) ... test the switch argument value 
    //     ... 
}
catch (CommandLineException e)
{
    Console.WriteLine(e.Message);
}

You can find more examples of use in the wiki.

The other way to use the library is to declare arguments by using attributes and thus make your code even more elegant:

// fields of this class will be bound
class ParsingTarget
{
    //class has several fields and properties bound to various argument types

    [SwitchArgument('s', "show", true, Description = "Set whether show or not")]
    public bool show;

    private bool hide;
    [SwitchArgument('h', "hide", false, Description = "Set whether hid or not")]
    public bool Hide
    {
        get { return hide; }
        set { hide = value; }
    }

    [ValueArgument(typeof(decimal), 'v', "version", Description = "Set desired version")]
    public decimal version;

    [ValueArgument(typeof(string), 'l', "level", Description = "Set the level")]
    public string level;

    [ValueArgument(typeof(Point), 'p', "point", Description = "specify the point")]
    public Point point;

    [BoundedValueArgument(typeof(int), 'o', "optimization", 
        MinValue = 0, MaxValue = 3, Description = "Level of optimization")]
    public int optimization;

    [EnumeratedValueArgument(typeof(string),'c', "color", AllowedValues = "red;green;blue")]
    public string color;
}

As Andreas Kroll pointed out - it can be useful to define set of arguments that cannot be used together or set of arguments, from which at least one argument must be used. This is now possible through Certifications collection of the parser and ArgumentCertification objects. They can also be defined declaratively using attributes, here is an example:

// exactly one of the arguments x, o, c must be used
[ArgumentGroupCertification("x,o,c", EArgumentGroupCondition.ExactlyOneUsed)]
// only one of the arguments f, u must be used
[ArgumentGroupCertification("f,u", EArgumentGroupCondition.OneOrNoneUsed)]
// arguments j and k can not be used together with arguments l or m
[DistinctGroupsCertification("j,k","l,m")]
public class Archiver
{
    [ValueArgument(typeof(string), 'f', "file", Description="Input from file")]
    public string InputFromFile;

    [ValueArgument(typeof(string), 'u', "url", Description = "Input from url")]
    public string InputFromUrl;

    [ValueArgument(typeof(string), 'c', "create", Description = "Create archive")]
    public string CreateArchive;

    [ValueArgument(typeof(string), 'x', "extract", Description = "Extract archive")]
    public string ExtractArchive;

    [ValueArgument(typeof(string), 'o', "open", Description = "Open archive")]
    public string OpenArchive;

    [SwitchArgument('j', "g1a1", true)]
    public bool group1Arg1;

    [SwitchArgument('k', "g1a2", true)]
    public bool group1Arg2;

    [SwitchArgument('l', "g2a1", true)]
    public bool group2Arg1;

    [SwitchArgument('m', "g2a2", true)]
    public bool group2Arg2;
}

commandlineparser's People

Contributors

alexandre-lecoq avatar dependabot[bot] avatar eapyl avatar gojimmypi avatar j-maly avatar prog-rajkamal avatar stefh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

commandlineparser's Issues

Problems opening solution with Visual Studio 2015

when attempting to open in Visual Studio 2015, I see several of these errors:

error : The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

indeed I don't even have a DotNet directory, let alone any Microsoft.DotNet.Props files in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0for VS 2015\

I tried manually commenting the line in the .xproj files, but then Visual Studio just explodes with a "fatal error" message when attempting to open the solution.

I assume you are using the not-yet-fully released VS2017? :)

Optional short names

Short names are mandatory for all arguments. This can be difficult for applications with many recognized arguments.

nullable int always set to 0?

  [ValueArgument(typeof(int), "MaxRequestLogCount", Optional = true, DefaultValue = null)]
  public int? MaxRequestLogCount { get; set; }

When not providing this argument, the default value is set to 0 instead of null ? Do I miss something?

And typeof(int?) crashes ?

  [ValueArgument(typeof(int?), "MaxRequestLogCount", Optional = true, DefaultValue = null)]
  public int? MaxRequestLogCount { get; set; }

Can't override Argument.Parse in my own argument class

Looking at the code the virtual Parse method is marked as internal. I can't extend from Argument (or one of its subclasses) and override Parse. This completely negates me from using this library to parse a command line with multiple strings for a single value. For example, if I try to add a convert handler to a ValueArgument it is just passed a single string and I need multiple strings to convert to my value type.

Suggestion: Argument file support

For use cases like Windows Planned Tasks or longer, auto generated commandlines using a textfile instead of commandline has advantages. I just checked successfully, a single line of code is enough to get full argument file support for CommandLineParser :

MyApp.exe "C:\Configs\MyCmdlineFile.txt"

VB.NET (checked)

Sub Main(args() As String)

Dim MyOptionsClass As new cMyOptionsClass
Dim clParser As New CommandLineParser.CommandLineParser
Try
     clParser.ExtractArgumentAttributes(MyOptionsClass)

    ' JUST ADD THIS LINE:
    If args IsNot Nothing AndAlso args.Count = 1 AndAlso File.Exists(args(0)) = True Then args= File.ReadAllText(args(0)).Trim.Split(New String(){" ", vbCrLf}, StringSplitOptions.RemoveEmptyEntries)

    clParser.ParseCommandLine(args)

    ' Here we go using values ...

    Catch clEx As CommandLineException
            Console.WriteLine(clEx.Message)

    Catch ex As Exception
            Console.WriteLine(Ex.Message)
End Try
End Sub

C# (unchecked!, sorry)

static class MyApp
{	public static void Main(string[] args)
	{
		cMyOptionsClass MyOptionsClass = new cMyOptionsClass();
		CommandLineParser.CommandLineParser clParser = new CommandLineParser.CommandLineParser();
		try {
			clParser.ExtractArgumentAttributes(MyOptionsClass);

			// JUST ADD THIS LINE:
			if (args != null && args.Count == 1 && File.Exists(args(0)) == true)
				args = File.ReadAllText(args(0)).Trim.Split(new string[] {
					" ",
					Strings.Chr(13) + Strings.Chr(10)
				}, StringSplitOptions.RemoveEmptyEntries);

			clParser.ParseCommandLine(args);

			// Here we go using values ...

		} catch (CommandLineException clEx) {
			Console.WriteLine(clEx.Message);

		} catch (Exception ex) {
			Console.WriteLine(ex.Message);
		}
	}
}

Maybe this could be a switchable, build-in feature in a further version or it is worth to add to docu.

How to write out ALL arguments and their values?

Using ShowParsedArguments() it 's very easy to write parsed arguments to console.

I'm looking for a similar way to report everything my parsingtarget class holds (varnames / values) to console. This can give user an overview of complete set (given parameters, used default values).

After parsing I have access to parsers argument collection, but the PrintValueInfo() method of the args is internal, so a simple loop cannot do the job.

Spelling error

In Messages.cs line 59:
public static string EXC_GROUP_DISTINCT = "None of these argumens: {0} can be used together with any of these: {1}.";

Arguments is misspelled as argumens.

multiple items not parsed

this argument will not be correctly filled:

[ValueArgument(typeof(string), Argument.UnsetShortNameChar, "types", 
  Optional = true, AllowMultiple = true, Description = "The file-types to process")]
public string[] FileTypes { get; set; }

commandline:
--types png jpg pdf

only the first argument (png) is assigned and the other 2 are interpreted as "additional arguments"

How is ArgumentRequiresOtherArgumentsCertification supposed to work?

I have defined my arguments as:

[DistinctGroupsCertification("s", "h,p")]
    [ArgumentRequiresOtherArgumentsCertification("h", "p,c,i,o")]
    internal class CommandLineArguments
    {
         ValueArgument(typeof(string), 's', "serverName", Description = "The friendly name given to the rabbit server connection.")]
        public string ServerName { get; set; }

        [ValueArgument(typeof(string), 'h', "hostName", Description = "The fully qualified host name of the rabbit server.")]
        public string ServerHostName { get; set; }

        [ValueArgument(typeof(int), 'p', "port", Description = "The port that should be used to connect to the rabbit server.", DefaultValue = 5672)]
        public int Port { get; set; }

        [RegexValueArgument('c', "credentials", CredentialsRegEx,
            Description =
                "The username and password that needs to be used to connect to the rabbit server.  This needs to be in the format username|password")]
        public string Credentials { get; set; }

        [ValueArgument(typeof(string), 'v', "virtualHost", Description = "The virtual host on the rabbit server that contains the scribe exchanges.", DefaultValue = "v.pds.ren.scribe")]
        public string ScribeVirtualHost { get; set; }

        [ValueArgument(typeof(string), 'i', "input", Description = "The scribe input exchange.", DefaultValue = "e.pds.tools.scribe.input")]
        public string ScribeInputExchange { get; set; }

        [ValueArgument(typeof(string), 'o', "output", Description = "The scribe output exchange.", DefaultValue = "e.pds.tools.scribe.output")]
        public string ScribeOutputExchange { get; set; }
}

When I run the application and pass the following on the command line:

-h dwerecrq01.hq.bn-corp.com -c renscribeui@Lithium3

I'm getting a CommandLineException thrown that contains this message:

None of these arguments: h can be used together with any of these: p,c,i,o.

I expected that the parse should of passed as I had default values for p, i, and o.

I'm confused as to why I'm getting a message informing me that I can't use p,c,i,o with h.

Thanks

-marc

Add license

Could you please add license to the project? I hope it will be any 'free' license (MIT?). Thanks!

BoundedValueArgument<int> throws NRE when used as Attribute

public class CommandLineArguments
{
[BoundedValueArgument(typeof(int), 'd', "duration", Description = "The duration of the acoustic data used in the adaptation.", ValueOptional = true, MinValue = 0, DefaultValue = 0)]
public int Duration { get; set; }
}

Parsing with:

using (var parser = new CommandLineParser())
{
var arguments = new CommandLineArguments();
parser.ExtractArgumentAttributes(arguments);
parser.ParseCommandLine(args);
}

throws NRE here:
at CommandLineParser.Arguments.BoundedValueArgumentAttribute.set_ValueOptional(Boolean value)

Prevent argument value from being printed to console

The ShowUsage() and ShowParsedArguments() methods will print all the arguments supplied to the console.

One of the arguments that I have for my application is a password.

How can I prevent the password from being show in the clear when ShowUsage() and ShowParsedArguments() called?

Thanks

marc

Not signed

warning BC41997: Referenced assembly 'CommandLineArgumentsParser, Version=3.0.7.0, culture=neutral, PublicKeyToken=null' does not have a strong name.

Could you guys create a .snk file and sign the dll please?

Combination of arguments

This could be an enhancement. There can be cases where combination of arguments have to be looked at to get full list of arguments for the application and treat them as valid input.

For example, let's say the app can accept 5 arguments. For simplicity, lets say its a,b,c,d,e. So there could be cases, where

  1. if a is provided, then b should not be provided.
  2. if c is provided, then a and d are also required.

All this, though might look like application specific logic, many users will have similar need. Though it might not be possible to cover all such kind of rules, but some of these basic ones could be added as part of default support.

BTW, thanks for this great utility library.

Is there an option to allow using just long versions of parameters?

I have some code I want to add a parameter to, but I don't want to have a short 1 character version, I just want the long-version. Is there a way to do that? If not, I'd like to request as a feature enhancement :)

I could add it as one of the unused characters, but I can see that as getting messy, as some of these options, I don't want to be used on a regular easy going basis :)

       Hugh

Default value for non-existing argument

Hello, thank you for the great library.

Is it possible to set different default values for ValueArgument if it is passed but without any value and if it is not passed at all? E.g.

internal class Arguments
{
    [ValueArgument(typeof(string), 'a', "argument", ValueOptional = true, DefaultValueNonExisting = "", DefaultValue = null, Optional = true)]
    public string Value { get; set; }
}
  • Value will be 'Argument':
 my-tool.exe -a Argument
  • Value will be "":
my-tool.exe
  • Value will be 'null':
my-tool.exe -a

Thanks

Invalid parsing when argument value begins with a slash

If you for example have:

--filePath /root/folder

You will get the error:

Grouping of multiple short name arguments in one word(e.g. -a -b into -ab) is allowed only for switch arguments.Argument r is not a switch argument.

Surrounding the path with quotation marks doesn't help.

Suggestion: File location default to current directory

hi,

Had a question on FileArgument. When we use the FileArgument, do we always have to give the full path? With the FileMustExist condition set to true, the library will try to validate if file exists or not. In many cases, the file might be available in the same directory as the current executable for which the arguments are being passed. So I think that in such cases, it would be simpler to pick up the file from the current directory instead of always having to provide the full file path. This way, the size of the command line argument also can be shortened and can be kept less cluttered, when dealing with multiple arguments. Wherever needed, we can still continue to provide the full file path.

So similar to FileMustExist attribute, if we had similar attribute, say CheckCurDir, which the user can use to indicate if the file check must happen after considering the current directory path. So in such a case, we can first get the current execution directory and then try to see if File exists in current directory. If yes, then update the parsed argument value to full path after appending the directory. If the file is not found in current directory, then try verifying as if the given value is a full path.

Thanks!

.NET parsing issue

I ran into this problem with the .NET args parsing, so this isn't a problem in CommandLineParser, but I thought I'd mention as it can make using your package challenging where there are arguments that have quoted paths. When passing a path having spaces as an argument, you have to double quote the path to make sure it's consumed as a single argument. The problem is that when the path has a trailing backslash followed by the closing double quote, the .NET parser treats it as an escaped double quote and any trailing options following get munged into that argument. I am able to work around it by looking for a double quote in the argument and replacing it with a backslash so long as it's the last argument on the command line. MSDN's remarks on command line processing notes the behavior which is how it acts, even if it happens to cause difficulties working with quoted paths:

If a double quotation mark follows two or an even number of backslashes, each proceeding backslash pair is replaced with one backslash and the double quotation mark is removed. If a double quotation mark follows an odd number of backslashes, including just one, each preceding pair is replaced with one backslash and the remaining backslash is removed; however, in this case the double quotation mark is not removed.

Here's a couple of examples,

With path statement last:

C:\tmp>DirectorySearch.exe -f output.csv -d "C:\Program Files\"
Parsing results:
        Command line:
-f output.csv -d C:\Program Files"

        Parsed Arguments:
Argument: f(filename), type: String, value: output.csv (converted from: output.csv)
Argument: d(directory), type: String, value: C:\Program Files" (converted from: C:\Program Files")

        Arguments not specified:
Argument: h(help) value: 0

        Additional arguments:

It sees both arguments, but the path contains a double quote rather than the trailing backslash. This can be worked around by replacing the escaped quote, but it requires the path always be in last position as an argument.

With path statement first:

C:\tmp>DirectorySearch.exe -d "C:\Program Files\" -f output.csv

This triggers an exception because the -f argument is required:


Required arguments missing. Please see usage:

DirectorySearch

Usage:
        -f, --filename... Filename to receive catalog data

        -d, --directory... Directory root to catalog

        -h, --help[optional]... DirectorySearch command line arguments


Parsing results:
        Command line:
-d C:\Program Files" -d output.csv

        Parsed Arguments:
Argument: d(directory), type: String, value: C:\Program Files" -d output.csv (converted from: C:\Program Files" -d output.csv)

        Arguments not specified:
Argument: f(filename), type: String, value:  (converted from: )
Argument: h(help) value: 0

        Additional arguments:

In this case, the -f and filename are consumed by the -d. Again, this is a problem with the .NET parsing of the command line, here's the args variable from the second argument:
`

  •   args	{string[2]}	string[]
      [0]	"-d"	string
      [1]	"c:\\program files\" -f output.csv"	string
    
      Environment.CommandLine	"\"C:\\Users\\me\\documents\\visual studio 2017\\Projects\\DirectorySearch\\DirectorySearch\\bin\\Debug\\DirectorySearch.exe\" -d \"c:\\program files\\\" -f output.csv"	string
    

`

Not sure if there's a good workaround that can be done in your package given you might actually want the escaped quotes in some cases (maybe a decorator denoting a path). I know that this particular argument is intended to be path, so I can make allowances for it, but it does make it more difficult as I have to require the user to order the arguments such that the path is last which allows me to use your package (much easier for me) or I have to directly work with the Environment.CommandLine to pick out the bits I need and essentially build my own parser specifically to handle this..

Enumerable argument type?

Is it possible to define an argument that accepts a list of values? Something like:

command.exe --reportTypes 1 4 5

Thanks!

Reverse-parsing - generate commandline from arguments

CommandLineParser.CommandLineParser parser = new CommandLineParser.CommandLineParser();
MyCommandLineOption options = new MyCommandLineOption();
parser.ExtractArgumentAttributes(options);
parser.ParseCommandLine(args);

It would be helpfull if its possible to do this reverse for generating a command string:

MyCommandLineOption options = new MyCommandLineOption();
option.p1 = "Yes we can";
option.p2 = true;
String cmd = option.ToParameterString(); // cmd should be: "-p1 Yes we can -p2"

New NuGet

Can you please create a new NuGet (version 3.0.5) and publish that version to NuGet.org ?

Or maybe add me as an author/owner so that I can also upload?

Regex

Any chance this powerfull regex argument extension will be implemented with attribute support?
It would extend the early automated validating possibilities alot! GUIDs, email addresses, IP addresses and many more could be done with ...

Your given source example 'RegexCertifiedArgument' works great, but writing an attribute aupport class is far beyond my .NET skills :)

Blank and example output

Many thanks for fast implementation of regex-arguments and full value diplaying!
Both work like a charm and help a lot: Whole non auto validation has shrinked to just two lines with!

Two very small issues:

  • Listing of arguments with AllowMultiple:= true needs a blank between values :

Output of .ShowParsedArguments(true) :
Argument: t(IDtags), type: String, occured 2x values: #ID01#ID02

Here values #ID01 and #ID02 seems to be one single string.

  • RegEx mismatch could show value of its example argument, if defined:

Argument 'id2' does not match the regex pattern '#[^ ]+'.

With attribute Example:= "#MyID" set , this could be:

Argument 'id2' does not match the regex pattern '#[^ ]+'. Valid example: #MyID

This could be helpfull, because of maybe not every user of a commandline tool speaks RegEx fluently.

Impossible to override CertifiedValueArgument.Certify

Certify is declared internal in CertifiedValueArgument, so it's not possible to extend the library by creating custom argument types as described in the documentation (in RegexCertifiedArgument)

Could you please remove the internal attribute?

SwitchArgument does not set parser field (version 3.0.4)

I have a parsing target class:

[ArgumentGroupCertification("i,r", EArgumentGroupCondition.ExactlyOneUsed)]
internal class ParsingTarget
{
    [SwitchArgument('i', "install", true, Description = "Install the tamper file")]
    public bool Install;

    [SwitchArgument('r', "remove", false, Description = "Remove the tamper file")]
    public bool Remove;

    [ValueArgument(typeof(string), 'e', "exe", Description = "Full path to the exe file", Optional = false)]
    public string ExePath;
}

With command line -i -e DummyFile and parsing code:
ParsingTarget p = new ParsingTarget();
parser.ExtractArgumentAttributes(p);
parser.ParseCommandLine(args);

The p.Install field does not get set to true.

Sample VS2105 solution showing the issue attached.

TestCmdParser.zip

Missing docu 'multiple values with declarative syntax'

"If you are using attributes (declarative syntax), you need to use the attribute on an array or list property/field"

Tried it in many ways (array, List, ...) with public var or property. In any case all i got was this error:

Type System.Collections.Generic.List`1[System.String] of argument 123 is not a built-in type.Set ConvertValueHandler to a conversion routine for this type or define static method Parse(string stringValue, CultureInfo cultureInfo) that can Parse your type from string.

One of my tried defs:

[ValueArgument(typeof(List), 't', "IDtag", AllowMultiple = true, Description = "desc to ID tags")]
public List SGIDtag { get; set; }

Called with:

myapp.exe -t val1 val2
or
myapp.exe -t "123" "456"

How to use multiple values with default value ?

This code

[ValueArgument(typeof(string), 'u', "Urls", Description = "URL(s) to listen on", Optional = true, AllowMultiple = true, DefaultValue = "http://localhost:9090/")]
            public string[] Urls;

Throws exception:

Unhandled Exception: System.ArgumentException: The collection argument 'urls' must contain at least one element.
   at WireMock.Validation.Check.NotEmpty[T](IList`1 value, String parameterName)

Option that allows additional parameters

The existing option
AdditionalArgumentsSettings.AcceptAdditionalArguments = true
throws an exception UnknownArgumentException if a not defined parameter passed.
I need an option to allow unknown arguments.

EnumeratedValueArgument w/ Enum

At a glance, I'm not seeing a method of using an enum along with EnumeratedValueArgument, specifically when using a attribute style parsing target.

I was hoping for something like:

        public enum MyEnum
        {
            One,
            Two
        }

        [EnumeratedValueArgument(typeof(MyEnum), 'm', "myEnum")]
        public MyEnum ParsedEnum;

or perhaps:

public enum MyEnum
        {
            One,
            Two
        }

        public static Dictionary<MyEnum, string> EnumMapping = new Dictionary<MyEnum, string>()
        {
            { MyEnum.One, "do something with one" },
            { MyEnum.Two, "do something with two" },
        };

        [EnumeratedValueArgument(typeof(string), 'm', "myEnum", AllowedValues = string.Join(";", EnumMapping.Keys)]
        public string ParsedEnum;

but that gives:

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

any ideas on this sort of functionality?

Add support to native Guid type

Hi, i have tried to fork your project for make a PR but since you have used the new 2017 VS format i'm not able to do that.
So i ask you, if possible to add support to guid type simply adding a single line of code to the file

ValueArgument.cs

On method

protected virtual TValue DefaultConvert(string stringValue)

you have a lot of "if" statement for manage the native type and if you add this line of code

           if (valueType == typeof(Guid)) return (TValue)(object)Guid.Parse(stringValue);

just below the last if all works fine.
Thanks in advance

Using AcceptAdditionalArguments=false always throws exception

When setting the parser.AdditionalArgumentsSettings.AcceptAdditionalArguments to false it always throws an exception, regardless of the arguments provided.

Example:

var stateArgument = new EnumeratedValueArgument<string>('s', "state", "Filters the list for the specific state.", new[] { "open", "closed", "all" });

var parser = new CommandLineParser.CommandLineParser();
parser.Arguments.Add(stateArgument);

// parses just fine
parser.ParseCommandLine(new[] { "--state", "open" });

// when using AcceptAdditionalArguments=false it crashes with the same (valid arguments)
var crashingParser = new CommandLineParser.CommandLineParser();
crashingParser.Arguments.Add(stateArgument);
crashingParser.AdditionalArgumentsSettings.AcceptAdditionalArguments = false;
crashingParser.ParseCommandLine(new[] { "--state", "open" });

Fix: one additional if check in ParseAdditionalArguments.

Proposed fix as a pull request.

Question on field and row terminators

Thoughts on the best way to ask the user for field and row terminators? The code I'm giving as examples for my users are in VB.Net and I'd rather convert than parse the different command line options they give

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.