CliRun(Delegate, CliSettings) Method
Parses the command line arguments and runs the indicated command as delegate.
Namespace: DotMake.CommandLineAssembly: DotMake.CommandLine (in DotMake.CommandLine.dll) Version: 1.8.8
public static int Run(
Delegate cliCommandAsDelegate,
CliSettings settings = null
)
- cliCommandAsDelegate Delegate
-
The command as delegate.
([CliArgument] string argument1, bool option1) => { }
([CliArgument] string argument1, bool option1) => { return 0; }
async ([CliArgument] string argument1, bool option1) => { await Task.Delay(1000); }
MethodReference
- settings CliSettings (Optional)
-
The settings for the parser's grammar and behaviors.
Int32
The exit code for the invocation.
//Delegate-based model
//In Program.cs, add this simple code:
Cli.Run(([CliArgument] string argument1, bool option1) =>
{
Console.WriteLine($@"Value for {nameof(argument1)} parameter is '{argument1}'");
Console.WriteLine($@"Value for {nameof(option1)} parameter is '{option1}'");
});
//Or:
Cli.Run(Method);
void Method([CliArgument] string argument2, bool option2)
{
Console.WriteLine($@"Value for {nameof(argument2)} parameter is '{argument2}'");
Console.WriteLine($@"Value for {nameof(option2)} parameter is '{option2}'");
}
//In Program.cs, add this simple code for returning exit code:
return Cli.Run(([CliArgument] string argument1, bool option1) =>
{
Console.WriteLine($@"Value for {nameof(argument1)} parameter is '{argument1}'");
Console.WriteLine($@"Value for {nameof(option1)} parameter is '{option1}'");
return 0;
});