A simple getopt styled command line library.
Install-Package deniszykov.CommandLine
For .NET Core Hosted environment:
Install-Package deniszykov.CommandLine.Hosted
To start, you need to configure the entry point to the application:
public class Program
{
private static int Main(string[] arguments) =>
CommandLine
.CreateFromArguments(arguments)
.Use<Program>() // set class with verbs/commands
.Run();
//
// Usage: myapp.exe hello --name <name>
//
public static int Hello(string name)
// ^ ^
// Verb Option
{
Console.WriteLine("Hello " + name + "!");
return 0; // exit code
}
}
Example Code / .NET Hosted Example Code
CommandLine
relies on reflection to find method to invoke.
This method should return int
value which is interpreted as Exit Code of application.
Asynchronous entry points and methods are also supported. To do this, use method RunAsync()
and Task<int>
as return type.
When you could request help for your application:
> myapp /?
This test application. Type /? for help.
Verbs:
HELLO Says hello to specified 'name'.
Or invoke Hello(string name)
with following command:
> myapp hello --name Jake
Hello Jake!