Settings
When you create a new instance of AppRunner<T>
you can pass an instance new AppSettings
object.
Here are the settings you can change:
Show argument details#
Shows type information of arguments in help text. Enabled by default.
Method argument mode#
Possible values :
- Parameter (default)
- Option
When method argument mode is set to parameter, all arguments of methods are treated as parameters and don't need any names to be passed through command line.
Caution
Order of passing parameters matter in this mode
When method argument mode is set to option, all arguments of methods are treated as options and need a name to be passed.
Important
This is only applicable for methods and not constructors. For constructors, all arguments are options only
Enable version option#
True by default. It adds an additional option to the root command. It shows version of the application.
Case#
1 2 3 4 5 6 7 8 9 10 11 12 |
|
by default this would result into something like this:
1 2 3 4 5 6 7 8 9 10 |
|
Command line conventions are different from C# conventions and the usual pascal casing of method names or camel casing of parameter names may not be suitable for command line arguments.
You can continue to develop you classes and method in normal C# conventions and tell library to transform them into the desired casing.
There are 5 modes available:
- DontChange
- LowerCase
- CamelCase
- KebabCase
- PascalCase
If you now use a different setting,
1 2 3 4 5 6 7 8 9 10 11 |
|
The result would something like this:
1 2 3 4 5 6 7 8 9 10 |
|
Note
This would not transform any name that you have overridden via [ApplicationMetadata]
, [Option]
or [Argument]
attributes.
Boolean mode#
In this library, there are two ways to parse boolean Options
Note
Boolean mod is applicable only for Options
and not for Arguments
1. Implicit#
This is the default mode.
In this mode, you don't pass the value true
or false
in the command line. These parameters are treated as flags. They are considered true
if they are present and false
when they are not.
For example:
1 |
|
In this case, value of parameter printValues
will be true
and in the following example,
1 |
|
value of parameter printValues
will be false.
Note
When using implicit boolean mode, it will result in an error, if the user tries to explicitly enter a value for parameter. In this instance, dotnet example.dll --printValues true
will result into an error.
When you check the help of a command, you if you see Flag
for a parameter, it means value is implit and does not require an explicit one.
Flag clubbing#
Clubbing of one letter options is supported. For example,
If a command has multiple boolean flags options like:
1 |
|
These can be passed either as
1 |
|
OR
1 |
|
2. Explicit#
If you want users to explicitly enter true or false, you need to set the boolean mode explicit. You can do that, by using the [Argument]
attribute as shown below:
1 2 3 4 |
|
Note
You can set BooleanMode = BooleanMode.Implicit
or BooleanMode = BooleanMode.Explicit
only for bool
or bool?
type options.
When you use explicit boolean mode, these scenarios are valid:
1 2 3 |
|
but dotnet example.dll MyCommand --capturelogs
is not valid and will result into error. It will only work in Implicit boolean mode.
When you check the help of a command, and you see Boolean
it means if you wan't to make it true, you need to pass an explicit value. If you don't pass one, it will default to false
automatically. Implicit and explicit are just ways to pass the value, under the hood they are just boolean parameters.