SimpleParser - parsing command line arguments made simple.
Just parse no sets etc. (maybe in the future)
Simple: b -b --bool
does work for bool arguments as well as f <filename> -f <filename> --file <fileName>
works for parameters.
For multiple strings use the ListOption
attribute which will return a List<string>
for Separator
-separated strings. Default: comma separated.
[Option("ShortName", "LongName", "DefaultValue")]
Main attribute for returning parameters after ShortName
or LongName
. Optionally specify a default value.
[BoolOption("ShortName", "Index")
Returns true/false if ShortName
exists. Optionally you can specify an Index
in args[]
to meet.
[IndexOption(Index)]
Returns args[Index]
.
[ListOption('Separator')]
Special Option for List<string>
properties.
Simply create a class called Options
for example and set its properties attributes like this:
class Options
{
[BoolOption("v", "verbose")]
public bool Verbose { get; set; }
[Option("o", "outdir")]
public string OutputDir { get; set; }
[ListOption("f", "files")]
public List<string> Files { get; set; }
[IndexOption(0)]
public string First { get; set; }
}
Now in your code run:
Options options = new Options();
X_ToolZ.SimpleParser.Parse(args, options);
and your options instance's properties should be populated.
Have fun!
MemphiZ AT X-ToolZ DOT com
Web: X-ToolZ.com (under construction)
Twitter: @XToolZ