Skip to content

Commit 532f27e

Browse files
SysLordremkop
authored andcommitted
Help uses HelpFactory
1 parent 1f9ad9d commit 532f27e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/picocli/CommandLine.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8155,6 +8155,7 @@ public static class Help {
81558155
private final ColorScheme colorScheme;
81568156
private final Map<String, Help> commands = new LinkedHashMap<String, Help>();
81578157
private List<String> aliases = Collections.emptyList();
8158+
private IHelpFactory helpFactory;
81588159

81598160
private IParamLabelRenderer parameterLabelRenderer;
81608161

@@ -8190,7 +8191,8 @@ public Help(CommandSpec commandSpec, ColorScheme colorScheme) {
81908191
this.aliases.add(0, commandSpec.name());
81918192
this.colorScheme = Assert.notNull(colorScheme, "colorScheme").applySystemProperties();
81928193
parameterLabelRenderer = createDefaultParamLabelRenderer(); // uses help separator
8193-
8194+
this.helpFactory = commandSpec.commandLine() != null ? commandSpec.commandLine().getHelpFactory() : new DefaultHelpFactory();
8195+
81948196
this.addAllSubcommands(commandSpec.subcommands());
81958197
}
81968198

@@ -8203,6 +8205,10 @@ public Help(CommandSpec commandSpec, ColorScheme colorScheme) {
82038205
/** Returns the {@code ColorScheme} model that this Help was constructed with.
82048206
* @since 3.0 */
82058207
public ColorScheme colorScheme() { return colorScheme; }
8208+
8209+
/** Returns the {@code ColorScheme} model that this Help was constructed with.
8210+
* @since 2.9 */
8211+
private IHelpFactory getHelpFactory() { return helpFactory; }
82068212

82078213
/** Option and positional parameter value label renderer used for the synopsis line(s) and the option list.
82088214
* By default initialized to the result of {@link #createDefaultParamLabelRenderer()}, which takes a snapshot
@@ -8251,7 +8257,7 @@ public Help addAllSubcommands(Map<String, CommandLine> commands) {
82518257
* @return this Help instance (for method chaining) */
82528258
Help addSubcommand(List<String> commandNames, CommandLine commandLine) {
82538259
String all = commandNames.toString();
8254-
commands.put(all.substring(1, all.length() - 1), new Help(commandLine.commandSpec, colorScheme).withCommandNames(commandNames));
8260+
commands.put(all.substring(1, all.length() - 1), getHelpFactory().create(commandLine.commandSpec, colorScheme).withCommandNames(commandNames));
82558261
return this;
82568262
}
82578263

@@ -8262,7 +8268,8 @@ Help addSubcommand(List<String> commandNames, CommandLine commandLine) {
82628268
* @deprecated
82638269
*/
82648270
@Deprecated public Help addSubcommand(String commandName, Object command) {
8265-
commands.put(commandName, new Help(CommandSpec.forAnnotatedObject(command, commandSpec.commandLine().factory)));
8271+
commands.put(commandName,
8272+
getHelpFactory().create(CommandSpec.forAnnotatedObject(command, commandSpec.commandLine().factory), defaultColorScheme(Ansi.AUTO)));
82668273
return this;
82678274
}
82688275

0 commit comments

Comments
 (0)