The ParseArgs
class is to be used to parse CLI arguments in an enumerator fashion. Here is a copy-paste gist.
Sample usage:
string[] args;
string arg, type;
bool doTrace = false;
using (var parser = new ParseArgs(args))
{
while (parser.MoveNext())
{
if (parser.Is("--help"))
{
ShowUsage();
Environment.ExitCode = 0;
return;
}
else if (parser.Is("--trace"))
{
doTrace = true;
}
else if (parser.Is("--no-trace"))
{
doTrace = false;
}
else if (parser.Is(arg = "-t"))
{
if (parser.Remains(1))
{
parser.MoveNext();
if (type != null)
{
errors.Add("Type is already defined");
}
else
{
type = parser.Current;
}
}
else
{
errors.Add("Argument " + arg + " requires a value");
}
}
else
{
errors.Add("Unknown argument " + parser.Current);
}
}
}