@@ -8109,6 +8109,7 @@ public static class Help {
81098109 private final ColorScheme colorScheme;
81108110 private final Map<String, Help> commands = new LinkedHashMap<String, Help>();
81118111 private List<String> aliases = Collections.emptyList();
8112+ private IHelpFactory helpFactory;
81128113
81138114 private IParamLabelRenderer parameterLabelRenderer;
81148115
@@ -8144,7 +8145,8 @@ public Help(CommandSpec commandSpec, ColorScheme colorScheme) {
81448145 this.aliases.add(0, commandSpec.name());
81458146 this.colorScheme = Assert.notNull(colorScheme, "colorScheme").applySystemProperties();
81468147 parameterLabelRenderer = createDefaultParamLabelRenderer(); // uses help separator
8147-
8148+ this.helpFactory = commandSpec.commandLine() != null ? commandSpec.commandLine().getHelpFactory() : new DefaultHelpFactory();
8149+
81488150 this.addAllSubcommands(commandSpec.subcommands());
81498151 }
81508152
@@ -8157,6 +8159,10 @@ public Help(CommandSpec commandSpec, ColorScheme colorScheme) {
81578159 /** Returns the {@code ColorScheme} model that this Help was constructed with.
81588160 * @since 3.0 */
81598161 public ColorScheme colorScheme() { return colorScheme; }
8162+
8163+ /** Returns the {@code ColorScheme} model that this Help was constructed with.
8164+ * @since 2.9 */
8165+ private IHelpFactory getHelpFactory() { return helpFactory; }
81608166
81618167 /** Option and positional parameter value label renderer used for the synopsis line(s) and the option list.
81628168 * By default initialized to the result of {@link #createDefaultParamLabelRenderer()}, which takes a snapshot
@@ -8205,7 +8211,7 @@ public Help addAllSubcommands(Map<String, CommandLine> commands) {
82058211 * @return this Help instance (for method chaining) */
82068212 Help addSubcommand(List<String> commandNames, CommandLine commandLine) {
82078213 String all = commandNames.toString();
8208- commands.put(all.substring(1, all.length() - 1), new Help (commandLine.commandSpec, colorScheme).withCommandNames(commandNames));
8214+ commands.put(all.substring(1, all.length() - 1), getHelpFactory().create (commandLine.commandSpec, colorScheme).withCommandNames(commandNames));
82098215 return this;
82108216 }
82118217
@@ -8216,7 +8222,8 @@ Help addSubcommand(List<String> commandNames, CommandLine commandLine) {
82168222 * @deprecated
82178223 */
82188224 @Deprecated public Help addSubcommand(String commandName, Object command) {
8219- commands.put(commandName, new Help(CommandSpec.forAnnotatedObject(command, commandSpec.commandLine().factory)));
8225+ commands.put(commandName,
8226+ getHelpFactory().create(CommandSpec.forAnnotatedObject(command, commandSpec.commandLine().factory), defaultColorScheme(Ansi.AUTO)));
82208227 return this;
82218228 }
82228229
0 commit comments