Skip to content

Commit

Permalink
[#443] Bugfix: Subcommand aliases were not recognized in some cases.
Browse files Browse the repository at this point in the history
Closes #443
  • Loading branch information
remkop committed Aug 14, 2018
1 parent 127a266 commit 3d00695
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
34 changes: 34 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# picocli Release Notes

# <a name="3.5.2"></a> Picocli 3.5.2
The picocli community is pleased to announce picocli 3.5.2.

This is a bugfix release that fixes an issue where subcommand aliases were not recognized in some cases.

This is the thirty-eighth public release.
Picocli follows [semantic versioning](http://semver.org/).

## <a name="3.5.2"></a> Table of Contents
* [New and noteworthy](#3.5.2-new)
* [Promoted features](#3.5.2-promoted)
* [Fixed issues](#3.5.2-fixes)
* [Deprecations](#3.5.2-deprecated)
* [Potential breaking changes](#3.5.2-breaking-changes)

## <a name="3.5.2-new"></a> New and Noteworthy


## <a name="3.5.2-promoted"></a> Promoted Features
Promoted features are features that were incubating in previous versions of picocli but are now supported and subject to backwards compatibility.

No features have been promoted in this picocli release.

## <a name="3.5.2-fixes"></a> Fixed issues
- [#443] Bugfix: Subcommand aliases were not recognized in some cases. Thanks to [K. Alex Mills](https://github.com/kalexmills) for the bug report.

## <a name="3.5.2-deprecated"></a> Deprecations
No features were deprecated in this release.

## <a name="3.5.2-breaking-changes"></a> Potential breaking changes
This release has no breaking changes.



# <a name="3.5.1"></a> Picocli 3.5.1
The picocli community is pleased to announce picocli 3.5.1.

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ public CommandLine addSubcommand(String name, Object command) {
*/
public CommandLine addSubcommand(String name, Object command, String... aliases) {
CommandLine subcommandLine = toCommandLine(command, factory);
subcommandLine.getCommandSpec().aliases(aliases);
List<String> update = new ArrayList<String>(Arrays.asList(subcommandLine.getCommandSpec().aliases()));
update.addAll(Arrays.asList(aliases));
subcommandLine.getCommandSpec().aliases(update.toArray(new String[0]));
getCommandSpec().addSubcommand(name, subcommandLine);
CommandLine.Model.CommandReflection.initParentCommand(subcommandLine.getCommandSpec().userObject(), getCommandSpec().userObject());
return this;
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/picocli/CommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,33 @@ public void testCommandListReturnsAliases() {
assertSame(subMap.get("sub21"), subMap.get("sub21alias2"));
}

@Command(name = "cb")
static class Issue443TopLevelCommand implements Runnable {
boolean topWasExecuted;
public void run() {
topWasExecuted = true;
}
}

@Command(name = "task", aliases = {"t"})
static class SubCommandWithAlias implements Runnable {
boolean subWasExecuted;
public void run() {
subWasExecuted = true;
}
}

@Test
public void testIssue443SubcommandWithAliasAnnotation() {
Issue443TopLevelCommand top = new Issue443TopLevelCommand();
SubCommandWithAlias sub = new SubCommandWithAlias();
CommandLine cmd = new CommandLine(top).addSubcommand("task", sub);
String[] args = {"t"};
List<Object> result = cmd.parseWithHandler(new RunAll(), args);
assertTrue("top was executed", top.topWasExecuted);
assertTrue("sub was executed", sub.subWasExecuted);
}

public static <T> Set<T> setOf(T... elements) {
Set<T> result = new HashSet<T>();
for (T t : elements) { result.add(t); }
Expand Down

0 comments on commit 3d00695

Please sign in to comment.