Cli.Parse Method
Definition
- Namespace
- DotMake.CommandLine
- Assembly
- DotMake.CommandLine.dll
Parse<TDefinition>(string[], CliSettings)
Parses a command line string array and returns the parse result for the indicated command.
public static CliRunnableResult Parse<TDefinition>(string[] args = null, CliSettings settings = null)
Parameters
argsstring[]The string array typically passed to a program. This is usually the special variable
argsavailable inProgram.cs(new style with top-level statements) or the string array passed to the program'sMainmethod (old style). If not specified or null,argswill be retrieved automatically from the current process via DotMake.CommandLine.CliParser.GetArgs().settingsCliSettingsThe settings for the parser's grammar and behaviors.
Returns
- CliRunnableResult
A CliRunnableResult providing details about the parse operation and methods for binding and running.
Type Parameters
TDefinitionThe definition class for the command. A command builder for this class should be automatically generated by the source generator.
Examples
//If you need to examine the parse result, such as errors:
var result = Cli.Parse<RootCliCommand>(args);
if (result.ParseResult.Errors.Count > 0)
{
}
Parse<TDefinition>(string, CliSettings)
Parses a command line string and returns the parse result for the indicated command.
public static CliRunnableResult Parse<TDefinition>(string commandLine, CliSettings settings = null)
Parameters
commandLinestringThe command line string that will be split into tokens as if it had been passed on the command line. Useful for testing command line input by just specifying it as a single string.
settingsCliSettingsThe settings for the parser's grammar and behaviors.
Returns
- CliRunnableResult
A CliRunnableResult providing details about the parse operation and methods for binding and running.
Type Parameters
TDefinitionThe definition class for the command. A command builder for this class should be automatically generated by the source generator.
Examples
//If you need to examine the parse result, such as errors:
var result = Cli.Parse<RootCliCommand>("NewValueForArgument1 --option-1 NewValueForOption1");
if (result.ParseResult.Errors.Count > 0)
{
}