Skip to content

Commit

Permalink
fix: ensure clustering options is detected correctly when subcommands…
Browse files Browse the repository at this point in the history
… added via AddSubcommand (#393)
  • Loading branch information
natemcmaster authored Sep 13, 2020
1 parent 0c9fe6b commit 21a73b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/CommandLineUtils/CommandLineApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ public void AddSubcommand(CommandLineApplication subcommand)
AssertCommandNameIsUnique(name, null);
}

subcommand.Parent = this;

Commands.Add(subcommand);
}

Expand Down
15 changes: 15 additions & 0 deletions test/CommandLineUtils.Tests/CommandLineProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ public void ItInfersClusterOptionsCannotBeUsed_MultiCharShortNameInSubcommand()
Assert.False(app.ClusterOptions);
}

[Fact]
public void ItInfersClusterOptionsCannotBeUsed_MultiCharShortNameViaAddedSubcommand()
{
var app = new CommandLineApplication();
var subcmd = new CommandLineApplication
{
Name = "sub"
};
subcmd.Option("-au|--auth", "Verbose output", CommandOptionType.NoValue);
app.AddSubcommand(subcmd);
Assert.False(app.ClusterOptionsWasSetExplicitly);
app.Parse("sub", "-au");
Assert.False(app.ClusterOptions);
}

[Fact]
public void ItInfersClusterOptionsCannotBeUsed_MultiCharShortNameAttribute()
{
Expand Down

0 comments on commit 21a73b3

Please sign in to comment.