|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Linq; |
5 | 6 | using Xunit; |
6 | 7 | using Xunit.Abstractions; |
7 | 8 |
|
@@ -94,5 +95,47 @@ public void KeepsDefaultValues() |
94 | 95 | Assert.Equal("a", app3.Model.Arg1); |
95 | 96 | Assert.Equal(new[] { "b", "c" }, app3.Model.Arg2); |
96 | 97 | } |
| 98 | + |
| 99 | + [Subcommand(typeof(ACommand))] |
| 100 | + public class Program |
| 101 | + { |
| 102 | + } |
| 103 | + |
| 104 | + [Command("a")] |
| 105 | + [Subcommand(typeof(BCommand))] |
| 106 | + public class ACommand |
| 107 | + { |
| 108 | + [Argument(0)] |
| 109 | + public string? Arg1 { get; set; } |
| 110 | + } |
| 111 | + |
| 112 | + [Command("b")] |
| 113 | + public class BCommand |
| 114 | + { |
| 115 | + [Argument(0)] |
| 116 | + public string? Arg1 { get; set; } |
| 117 | + } |
| 118 | + |
| 119 | + [Fact] |
| 120 | + public void SameArgumentInSubcommandsCallingACommand() |
| 121 | + { |
| 122 | + var app1 = new CommandLineApplication<Program>(); |
| 123 | + app1.Conventions.UseDefaultConventions(); |
| 124 | + var result = app1.Parse("a", "any-value"); |
| 125 | + var command = result.SelectedCommand as CommandLineApplication<ACommand>; |
| 126 | + Assert.NotNull(command); |
| 127 | + Assert.Equal("any-value", command.Model.Arg1); |
| 128 | + } |
| 129 | + |
| 130 | + [Fact] |
| 131 | + public void SameArgumentInSubcommandsCallingBCommand() |
| 132 | + { |
| 133 | + var app1 = new CommandLineApplication<Program>(); |
| 134 | + app1.Conventions.UseDefaultConventions(); |
| 135 | + var result = app1.Parse("a", "b", "any-value"); |
| 136 | + var command = result.SelectedCommand as CommandLineApplication<BCommand>; |
| 137 | + Assert.NotNull(command); |
| 138 | + Assert.Equal("any-value", command.Model.Arg1); |
| 139 | + } |
97 | 140 | } |
98 | 141 | } |
0 commit comments