This repository is the fork of NDesk.Options 0.2.1 (callback-based program option parser for C#).
Original project link: http://www.ndesk.org/Options
Original project documentation: http://www.ndesk.org/doc/ndesk-options/NDesk.Options/
- Create Option Set
var p = new OptionSet ()
- Add argumets ( Important: if you need to get value in lambda you need
=
like:g|game=
)
p.Add("s|status=", n => Console.WriteLine("Status is "+ n));
- If it find your argument the lambda will called, othewise it will return it back
var unexpectedArguments = p.Parse(argsArray);
foreach(var arg in unexpectedArguments)
{
Console.WriteLine($"Unknown argument: {arg}");
}
Output:
> program.exe -s Ready
Status is Ready
> program.exe --status "Loading"
Status is Loading
> program.exe --anotherArgument 12
Unknown argument: --anotherArgument
Unknown argument: 12
var p = new OptionSet ()
// You can call: -n "Rick" or --name "Morty"
p.Add("n|name=", n => Console.WriteLine(n));
// You can call only with long argument: --name "Morty"
p.Add("name=", n => Console.WriteLine("First Name: " + n));
// Bool options usage: -s, you dont need `=` in case of bool option
p.Add("s|isSmart", s => Console.WriteLine(s != null));
// Int options usage: -a 11
p.Add("a|age=", (int a) => Console.WriteLine("Age: " + s));
var unexpectedArguments = p.Parse (args);
foreach(var arg in unexpectedArguments)
{
Console.WriteLine($"Unknown argument: {arg}");
}
program.exe --name "Morty" --surname "Smith" --sex "male" -a 13
First Name: Morty
Last Name: Smith
Age: 13
Unknown argument: --sex
Unknown argument: male
The project is licensed under the MIT license.