You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+76-1Lines changed: 76 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,7 @@ There are 2 kinds of arguments:
85
85
86
86
## Advanced scenarios
87
87
88
+
### Argument grouping
88
89
There are cases when you want to have different sets of arguments depending on one of the arguments.
89
90
90
91
The argument that will be used as the differentiator will be marked with the `ActionArgument` attribute. That argument must be specified.
@@ -95,7 +96,6 @@ A single property in a class can take part in many argument groups.
95
96
96
97
If a property will be common to all groups, you can use the `CommonArgument' attribute
97
98
98
-
99
99
```csharp
100
100
internalclassCommandLineOptions
101
101
{
@@ -135,3 +135,78 @@ internal class CommandLineOptions
135
135
136
136
}
137
137
```
138
+
139
+
### Argument position override
140
+
141
+
Sometimes you want to have a common parameter shared across multiple commands, but you want the position of it to be different in those two groups.
142
+
143
+
To do that, you use the constructor for the `ArgumentGroup` attribute that takes as the second argument the override position for that argument group.
144
+
145
+
In the example below, the common parameter `repos` is defined as required in position `1`.
146
+
For the group `Create` where no override position is specified, the parameter will be required at position `1`.
147
+
For the group `List` where the override position is specified, the parameter will be required at position `0`.
148
+
149
+
```csharp
150
+
classOverridePositionGroup
151
+
{
152
+
[ActionArgument]
153
+
publicActionAction { get; set; }
154
+
155
+
[ArgumentGroup(nameof(Action.Create))]
156
+
[RequiredArgument(0, "milestoneInputFile", "The file containing the list of milestones to create.")]
157
+
publicstringMilestoneFile { get; set; }
158
+
159
+
[ArgumentGroup(nameof(Action.List), 0)]
160
+
[ArgumentGroup(nameof(Action.Create))]
161
+
[RequiredArgument(1, "repos", "The list of repositories where to add the milestones to. The format is: owner\\repoName.", true)]
162
+
publicList<string> Repositories { get; set; }
163
+
}
164
+
```
165
+
166
+
### Background color
167
+
168
+
The parser will automatically detect the color to use when displaying help in a command prompt. There are a set of colors that are predefined depending on the console color.
169
+
170
+
You can specify different colors to be used by implementing the `IColor` interface and configuring the parser:
0 commit comments