Skip to content

Commit 21a73b3

Browse files
authored
fix: ensure clustering options is detected correctly when subcommands added via AddSubcommand (#393)
1 parent 0c9fe6b commit 21a73b3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/CommandLineUtils/CommandLineApplication.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ public void AddSubcommand(CommandLineApplication subcommand)
458458
AssertCommandNameIsUnique(name, null);
459459
}
460460

461+
subcommand.Parent = this;
462+
461463
Commands.Add(subcommand);
462464
}
463465

test/CommandLineUtils.Tests/CommandLineProcessorTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ public void ItInfersClusterOptionsCannotBeUsed_MultiCharShortNameInSubcommand()
159159
Assert.False(app.ClusterOptions);
160160
}
161161

162+
[Fact]
163+
public void ItInfersClusterOptionsCannotBeUsed_MultiCharShortNameViaAddedSubcommand()
164+
{
165+
var app = new CommandLineApplication();
166+
var subcmd = new CommandLineApplication
167+
{
168+
Name = "sub"
169+
};
170+
subcmd.Option("-au|--auth", "Verbose output", CommandOptionType.NoValue);
171+
app.AddSubcommand(subcmd);
172+
Assert.False(app.ClusterOptionsWasSetExplicitly);
173+
app.Parse("sub", "-au");
174+
Assert.False(app.ClusterOptions);
175+
}
176+
162177
[Fact]
163178
public void ItInfersClusterOptionsCannotBeUsed_MultiCharShortNameAttribute()
164179
{

0 commit comments

Comments
 (0)