No OptionList and OptionArray, and I cant find a way to parse a list; if the api changes, please update the wiki
alenwesker opened this issue · 6 comments
These two class just not exist in the code. Very annoying, where do you guys put these two.
I assume you're using the new 2.X version - those have been merged into the regular Option attribute and automatically applied when your type is an IEnumerable
. Check out the documentation for the latest version below:
https://github.com/gsscoder/commandline/wiki/Latest-Version#options
[Value(1, Min=1, Max=3)]
public IEnumerable<string> StringSeq { get; set; }
Still current version 2.3.0 isn't supporting OptionList and OptionArray.
@moh-hassan What features of OptionList or OptionArray are missing from the new 2.x alternative I listed above? There are no plans to bring the OptionList or OptionArray attributes back.
OptionArray:
All values specified after an OptionArray will be loaded into the array.
class Options
{
[OptionArray('c', "Cas")]
public string[] NameCase { get; set; }
}
e.g app -c pas camel none
all options after -c
are separated by space
Lists:
class Options
{
[OptionList('t', "tags")]
public IList<string> Tags { get; set; }
}
example:
app -t csharp:vbnet:cpp
All options after -t are separated by colon
see doc
They are different than the free values. They are distinct values without min or max as you describe in your example
How to modify the above code used in v 1.9.x to be used in v 2.x
Here you go. Min and Max define how many values are allowed, not a minimum or maximum integer value. Leave Max blank if you want it to be unbounded.
void Main()
{
Parser.Default.ParseArguments<Options>(
"-c pas camel none".Split())
.WithParsed(o => o.Dump())
.WithNotParsed(e => e.Dump());
Parser.Default.ParseArguments<Options>(
"-t csharp:vbnet:cpp".Split())
.WithParsed(o => o.Dump())
.WithNotParsed(e => e.Dump());
}
public class Options
{
[Option('c', Min = 1)]
public IEnumerable<string> NameCase { get; set; }
[Option('t', Min = 1, Separator=':')]
public IEnumerable<string> Tags { get; set; }
}
Great :) :)
It's working fine.
I run a demo Test:
Parser.Default.ParseArguments<Options4>(args)
.WithParsed(opts =>
{
foreach (var x in opts.NameCase)
{
Console.WriteLine(x);
}
Console.WriteLine("--------");
foreach (var x in opts.Tags)
{
Console.WriteLine(x);
}
})
.WithNotParsed(HandleParseError);
output:
pas
camel
none
--------
csharp
vbnet
cpp
I can catch the parameters.
So, NO NEED for OptionList and OptionArray
and they can be replaced by Option
.