Provides simpler management and checking of command-line arguments in an application.
using CLIHelper;
internal class Program
{
private enum MySwitch
{
// random switches for example
b,
v,
x,
// as long as the argument matches the name, it will parse
debug
}
// attributes can be on any one method that is marked as just 'static'
[Argument("arg1", CLIType.String, 1)]
[Switch("arg12", typeof(MySwitch), SwitchIdentifier.Slash, 2)]
[OptionalArgument("arg3", CLIType.String)]
[OptionalSwitch("arg4", typeof(MySwitch), SwitchIdentifier.Hyphen)]
static void Main()
{
var args = CLI.GetArguments(); // will return null if any parsing errors occurred, which in turn will be printed to the console
if (args != null)
{
// and now do what you need with your arguments
Console.WriteLine(args["arg1"].ToString());
Console.WriteLine(args["arg2"].GetEnumValue<MySwitch>());
}
}
}
- Check for entry method named
Main
to ensure clarity with attribute usage - Print out available arguments if none are provided
- Make use of
Description
metadata inCLIAttribute
- Replace
_
in enum value names with-
for complex switch arguments