mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-14 16:02:50 +08:00
parent
cec5fb4595
commit
f7befacd79
@ -1,7 +1,7 @@
|
||||
Title: Specifying Settings
|
||||
Order: 5
|
||||
Description: "How to define command line argument settings for your *Spectre.Console.Cli* Commands"
|
||||
Reference:
|
||||
Reference:
|
||||
- T:Spectre.Console.Cli.CommandSettings
|
||||
- T:Spectre.Console.Cli.CommandArgumentAttribute
|
||||
- T:Spectre.Console.Cli.CommandOptionAttribute
|
||||
@ -86,7 +86,9 @@ public int Count { get; set; }
|
||||
|
||||
## Arrays
|
||||
|
||||
`CommandArgument` can be defined as arrays and any additional parameters will be included in the value. For example
|
||||
### Argument Vector
|
||||
|
||||
One (exactly one) `CommandArgument` can be defined as an array, and any additional parameters will be included in the value. For example:
|
||||
|
||||
```csharp
|
||||
[CommandArgument(0, "[name]")]
|
||||
@ -95,6 +97,19 @@ public string[] Name { get; set; }
|
||||
|
||||
Would allow the user to run `app.exe Dwayne Elizondo "Mountain Dew" Herbert Camacho`. The settings passed to the command would have a 5 element array consisting of Dwayne, Elizondo, Mountain Dew, Herbert and Camacho.
|
||||
|
||||
A command can have only one argument vector, and it needs to be the last argument. (I.e. there can be no `CommandArgument` whose position is higher than that of the argument vector.)
|
||||
|
||||
### Option Arrays
|
||||
|
||||
A `CommandOption` can be defined as an array like the following:
|
||||
|
||||
```csharp
|
||||
[CommandOption("-n|--name <VALUES>")]
|
||||
public string[] Names { get; set; },
|
||||
```
|
||||
|
||||
This would allow the user to run `app.exe --name Dwayne --name Elizondo --name "Mountain Dew" --name Herbert --name Camacho` and would result in a 5 element array consisting of Dwayne, Elizondo, Mountain Dew, Herbert and Camacho.
|
||||
|
||||
## Constructors
|
||||
|
||||
`Spectre.Console.Cli` supports constructor initialization and init only initialization. For constructor initialization, the parameter name of the constructor must match the name of the property name of the settings class. Order does not matter.
|
||||
|
Loading…
x
Reference in New Issue
Block a user