diff --git a/src/main/java/picocli/CommandLine.java b/src/main/java/picocli/CommandLine.java index 9cdfe7c1d..288ef7940 100644 --- a/src/main/java/picocli/CommandLine.java +++ b/src/main/java/picocli/CommandLine.java @@ -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); @@ -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();} } diff --git a/src/test/java/picocli/MixinTest.java b/src/test/java/picocli/MixinTest.java index 5fcb8b7b7..9a4e44e2d 100644 --- a/src/test/java/picocli/MixinTest.java +++ b/src/test/java/picocli/MixinTest.java @@ -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()); + } }