Skip to content

Commit

Permalink
Fix and unit test for issue 1836.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfacoconut authored and remkop committed Oct 31, 2022
1 parent 94bc75d commit bcb9cec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/picocli/CommandLine.java
Expand Up @@ -7010,7 +7010,7 @@ public CommandSpec addMixin(String name, CommandSpec mixin) {
mixins.put(interpolator.interpolate(name), mixin);

initName(interpolator.interpolateCommandName(mixin.name()));
// TODO initAliases(mixin.aliases()); // should we?
initAliases(mixin.aliases()); // should we?
// TODO initCommandHierarchyWithResourceBundle(mixin.usageMessage().messages().resourceBundleBaseName(), );
initFrom(mixin);

Expand Down Expand Up @@ -7455,6 +7455,7 @@ public void updateCommandAttributes(Command cmd, IFactory factory) {
}
}

void initAliases(String[] aliases) { if (aliases != null) { this.aliases.addAll(Arrays.asList(aliases));}}
void initName(String value) { if (initializable(name, value, DEFAULT_COMMAND_NAME)) {name = value;} }
void initHelpCommand(boolean value) { if (initializable(isHelpCommand, value, DEFAULT_IS_HELP_COMMAND)) {isHelpCommand = value;} }
void initVersion(String[] value) { if (initializable(version, value, UsageMessageSpec.DEFAULT_MULTI_LINE)) {version = value.clone();} }
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/picocli/MixinTest.java
Expand Up @@ -1081,4 +1081,23 @@ public void testMixinLongOptionsMaxWidth() {

assertEquals(43, another.usageMessage().longOptionsMaxWidth());
}

@Command(aliases = {"ls"} )
public static class ListAliasMixin {
}

@Command(name="list")
public static class MyListCommand {
@Mixin() public ListAliasMixin aliasMixin;
}

@Command(subcommands = {MyListCommand.class})
public static class App_Issue1836 {
}

@Test
public void testIssue1836CommandAliasOnMixin() {
Help help = new Help(new App_Issue1836());
assertEquals("list, ls", help.commandList().trim());
}
}

0 comments on commit bcb9cec

Please sign in to comment.