Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and unit test for issue 1836 #1841

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -5995,13 +5995,13 @@ private Model() {}
* @since 4.0
*/
public interface IScope extends IGetter, ISetter {}
/** This interface provides access to an {@link IScope} instance.

/** This interface provides access to an {@link IScope} instance.
* @since 4.7
*/
public interface IScoped {
/** Get the {@link IScope} instance.
*
*
* @return {@link IScope} instance */
IScope getScope();
}
Expand Down 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 Expand Up @@ -9176,8 +9177,8 @@ private String defaultValueFromProvider() {
* @return whether this argument applies to all descendent subcommands of the command where it is defined
* @since 4.3 */
public ScopeType scopeType() { return scopeType; }
/** Check whether the {@link #getValue()} method is able to get an actual value from the current {@link #getter()}.

/** Check whether the {@link #getValue()} method is able to get an actual value from the current {@link #getter()}.
* @since 4.7 */
public boolean isValueGettable() {
if (getter instanceof IScoped) {
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/picocli/MixinTest.java
Original file line number Diff line number Diff line change
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());
}
}