|
9 | 9 | using System.Threading.Tasks;
|
10 | 10 | using FluentAssertions;
|
11 | 11 | using Xunit;
|
| 12 | +using static System.Environment; |
12 | 13 |
|
13 | 14 | namespace System.CommandLine.Tests.Binding
|
14 | 15 | {
|
@@ -160,6 +161,62 @@ public void If_service_is_not_found_then_an_error_results()
|
160 | 161 | exitCode.Should().Be(1);
|
161 | 162 | }
|
162 | 163 |
|
| 164 | + [Fact] |
| 165 | + public void If_no_symbol_was_passed_for_binding_then_the_error_message_suggests_a_fix_for_the_first_missing_symbol() |
| 166 | + { |
| 167 | + var boolOption = new Option<bool>("-o"); |
| 168 | + var stringArg = new Argument<string>("value"); |
| 169 | + |
| 170 | + var subcommand = new Command("TheCommand") |
| 171 | + { |
| 172 | + boolOption, |
| 173 | + stringArg |
| 174 | + }; |
| 175 | + |
| 176 | + var command = new RootCommand |
| 177 | + { |
| 178 | + subcommand |
| 179 | + }; |
| 180 | + |
| 181 | + subcommand.SetHandler((bool boolValue, string stringValue) => { }); |
| 182 | + |
| 183 | + var console = new TestConsole(); |
| 184 | + |
| 185 | + command.Invoke("TheCommand -o hi", console); |
| 186 | + |
| 187 | + console.Error.ToString().Should() |
| 188 | + .Contain( |
| 189 | + $"The SetHandler call for command 'TheCommand' is missing an Argument or Option for the parameter at position 0. Did you mean to pass one of these?{NewLine}Option<Boolean> -o"); |
| 190 | + } |
| 191 | + |
| 192 | + [Fact] |
| 193 | + public void If_no_symbol_was_passed_for_binding_subsequent_parameter_then_the_error_message_suggests_a_fix_for_the_first_missing_symbol() |
| 194 | + { |
| 195 | + var boolOption = new Option<bool>("-o"); |
| 196 | + var stringArg = new Argument<string>("value"); |
| 197 | + |
| 198 | + var subcommand = new Command("TheCommand") |
| 199 | + { |
| 200 | + boolOption, |
| 201 | + stringArg |
| 202 | + }; |
| 203 | + |
| 204 | + var command = new RootCommand |
| 205 | + { |
| 206 | + subcommand |
| 207 | + }; |
| 208 | + |
| 209 | + subcommand.SetHandler((bool boolValue, string stringValue) => { }, boolOption); |
| 210 | + |
| 211 | + var console = new TestConsole(); |
| 212 | + |
| 213 | + command.Invoke("TheCommand -o hi", console); |
| 214 | + |
| 215 | + console.Error.ToString().Should() |
| 216 | + .Contain( |
| 217 | + $"The SetHandler call for command 'TheCommand' is missing an Argument or Option for the parameter at position 1. Did you mean to pass one of these?{NewLine}Argument<String> value"); |
| 218 | + } |
| 219 | + |
163 | 220 | [Fact]
|
164 | 221 | public void Custom_types_can_be_bound()
|
165 | 222 | {
|
|
0 commit comments