This is the only sane .Net library for command-line option parsing I've found in the Web.
From my point of view it lacks only few features. The first is a trivial but working example at the beginning of the documentation to reduce entry level for new users because not everyone wants to read through the documentation.
Something like the following would be nice:
using System;
using CommandLine.OptParse;
class Options
{
[OptDef(OptValType.ValueOpt)]
[LongOptionName("greeting")]
public string Greeting = "Hello, world!";
}
class Program
{
static void Main()
{
Options options = new Options();
ParserFactory.BuildParser(options).Parse();
Console.WriteLine(options.Greeting);
}
}
Another thing that could be improved is exception handling. It would be better to have one exception type for invalid value case, including the following example from the documentation:
public string ExampleEnumPropAsString
{
get { return _exampleEnumProp.ToString(); }
set
{
switch (value.ToLower())
{
case "first": _exampleEnumProp = ExamplePropertyEnum.First; break;
case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break;
default:
throw new ArgumentException(
"Invalid value for the example-enum-prop option");
}
}
}
However, in the latter case it will be TargetInvocationException with inner exception ArgumentException.
And thanks for license change.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Welcome to Open Discussion
Great work!
This is the only sane .Net library for command-line option parsing I've found in the Web.
From my point of view it lacks only few features. The first is a trivial but working example at the beginning of the documentation to reduce entry level for new users because not everyone wants to read through the documentation.
Something like the following would be nice:
using System;
using CommandLine.OptParse;
class Options
{
[OptDef(OptValType.ValueOpt)]
[LongOptionName("greeting")]
public string Greeting = "Hello, world!";
}
class Program
{
static void Main()
{
Options options = new Options();
ParserFactory.BuildParser(options).Parse();
Console.WriteLine(options.Greeting);
}
}
Another thing that could be improved is exception handling. It would be better to have one exception type for invalid value case, including the following example from the documentation:
public string ExampleEnumPropAsString
{
get { return _exampleEnumProp.ToString(); }
set
{
switch (value.ToLower())
{
case "first": _exampleEnumProp = ExamplePropertyEnum.First; break;
case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break;
default:
throw new ArgumentException(
"Invalid value for the example-enum-prop option");
}
}
}
However, in the latter case it will be TargetInvocationException with inner exception ArgumentException.
And thanks for license change.