
Small helper library that provides a simple way to use System.CommandLine by just passing a bunch of functions into a builder and creating a command line application.
Usage
It works great with the newly introduced dotnet scripts. More about the scripts here.
Logic for how the library turns a function into a command is straightforward:
- each basic type (e.g. bool, string, int) parameter is turned into an argument
- each class parameter is turned into bunch of options, where each field is turned into an option. Default values from class declaration are respected.
- if return type is
intthen the command will return the value of the function. Otherwise, it will return 0.
Small example
This is a valid program that can be run from the command line:
return clapnet.CommandBuilder.
.
.;
More feature-rich example
Example with extra settings and more commands:
var builder = clapnet.CommandBuilder.;
return builder
.
.
.
.
.
.
.;
/// <summary>
/// Documentation for gather command
/// </summary>
/// <param name="test2">extra argument</param>
/// <param name="assert">other argument</param>
void
void
/// <summary>
/// This command will fail
/// </summary>
int
Now when called from the CLI it will print out:
Take a look at the examples directory for a simple example of how to use clapnet.