From dfe2134c06b6997133981bd29a3c86cbc454b81e Mon Sep 17 00:00:00 2001 From: zgjimhaziri Date: Thu, 31 Jul 2025 21:58:21 +0200 Subject: [PATCH 1/4] TA-4038: Implement custom help and beta tagging --- src/content-cli.ts | 6 ++++++ src/core/command/CustomHelp.ts | 19 +++++++++++++++++++ src/core/command/module-handler.ts | 14 +++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/core/command/CustomHelp.ts diff --git a/src/content-cli.ts b/src/content-cli.ts index 3bf4cd41..a849d0cb 100644 --- a/src/content-cli.ts +++ b/src/content-cli.ts @@ -6,6 +6,7 @@ import { Configurator, ModuleHandler } from "./core/command/module-handler"; import { Context } from "./core/command/cli-context"; import { VersionUtils } from "./core/utils/version"; import { logger } from "./core/utils/logger"; +import { ContentCLIHelp } from "./core/command/CustomHelp"; /** * Celonis Content CLI. @@ -24,6 +25,11 @@ if (!semverSatisfies(process.version, requiredVersion)) { // Global configuration options const program: Command = new Command(); +program.configureHelp({ + formatHelp: (cmd, helper) => new ContentCLIHelp().formatHelp(cmd, helper), + subcommandTerm:cmd => new ContentCLIHelp().subcommandTerm(cmd), + optionTerm: opt => new ContentCLIHelp().optionTerm(opt), +}); program.version(VersionUtils.getCurrentCliVersion()); program.option("-q, --quietmode", "Reduce output to a minimum", false); program.option("-p, --profile [profile]"); diff --git a/src/core/command/CustomHelp.ts b/src/core/command/CustomHelp.ts new file mode 100644 index 00000000..f5f38364 --- /dev/null +++ b/src/core/command/CustomHelp.ts @@ -0,0 +1,19 @@ +import { Command, Help } from "commander"; +import * as chalk from "chalk"; + +export class ContentCLIHelp extends Help { + + public subcommandTerm(cmd: Command): string { + const base = super.subcommandTerm(cmd); + return (cmd as any).isBeta === true + ? `${base} ${chalk.yellow("(beta)")}` + : base; + } + + public optionTerm(option: any): string { + const term = super.optionTerm(option); + return (option as any).isBeta === true + ? `${term} ${chalk.yellow("(beta)")}` + : term; + } +} diff --git a/src/core/command/module-handler.ts b/src/core/command/module-handler.ts index d88d384b..9925a787 100644 --- a/src/core/command/module-handler.ts +++ b/src/core/command/module-handler.ts @@ -1,6 +1,6 @@ import path = require("path"); import * as fs from "fs"; -import { Command, CommandOptions, OptionValues } from "commander"; +import { Command, CommandOptions, Option, OptionValues } from "commander"; import { Context } from "./cli-context"; import { logger } from "../utils/logger"; @@ -185,6 +185,13 @@ export class CommandConfig { return this; } + public betaOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): CommandConfig { + const option = new Option(flags, description).default(defaultValue); + (option as any).isBeta = true; + this.cmd.addOption(option); + return this; + } + public requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): CommandConfig { this.cmd.requiredOption(flags, description, defaultValue); return this; @@ -195,6 +202,11 @@ export class CommandConfig { return this; } + public beta(): CommandConfig { + (this.cmd as any).isBeta = true; + return this; + } + public action(handler: CommandHandler): void { this.cmd.action(async (): Promise => { try { From 021f58e4c3f64b0f5ee9edb0ab413e49419f448b Mon Sep 17 00:00:00 2001 From: zgjimhaziri Date: Thu, 31 Jul 2025 22:52:48 +0200 Subject: [PATCH 2/4] TA-4038: Add message printing for beta usage --- src/core/command/module-handler.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/core/command/module-handler.ts b/src/core/command/module-handler.ts index 9925a787..56a1b0a4 100644 --- a/src/core/command/module-handler.ts +++ b/src/core/command/module-handler.ts @@ -3,6 +3,7 @@ import * as fs from "fs"; import { Command, CommandOptions, Option, OptionValues } from "commander"; import { Context } from "./cli-context"; import { logger } from "../utils/logger"; +import * as chalk from "chalk"; export abstract class IModule { public abstract register(context: Context, commandConfig: Configurator): void; @@ -154,6 +155,8 @@ export class Configurator { */ export class CommandConfig { private deprecationMessage: string; + private isBetaCommand: boolean = false; + private betaOptions: string[]; constructor( private cmd: Command, @@ -203,6 +206,7 @@ export class CommandConfig { } public beta(): CommandConfig { + this.isBetaCommand = true; (this.cmd as any).isBeta = true; return this; } @@ -210,6 +214,8 @@ export class CommandConfig { public action(handler: CommandHandler): void { this.cmd.action(async (): Promise => { try { + this.printBetaNoticeIfBetaCommand(); + this.printBetaNoticeIfBetaOptions(); this.printDeprecationNoticeIfDeprecated(); await handler(this.ctx, this.cmd, this.cmd.opts()); } catch (error) { @@ -223,4 +229,18 @@ export class CommandConfig { logger.warn("⚠️ [DEPRECATION NOTICE] \n" + this.deprecationMessage); } } + + private printBetaNoticeIfBetaCommand(): void { + if (this.isBetaCommand) { + logger.info(chalk.yellow("This command is in beta and may change in future releases.")); + } + } + + private printBetaNoticeIfBetaOptions(): void { + for (const option of this.cmd.options) { + if ((option as any).isBeta) { + logger.info(chalk.yellow(`The option '${option.long}' is in beta and may change in future releases.`)); + } + } + } } From 69bfb14950b7026298922e436201451291432add Mon Sep 17 00:00:00 2001 From: zgjimhaziri Date: Thu, 31 Jul 2025 22:56:04 +0200 Subject: [PATCH 3/4] TA-4038: Refrain from option message if the command itself is in beta --- src/core/command/module-handler.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/command/module-handler.ts b/src/core/command/module-handler.ts index 56a1b0a4..feb8d927 100644 --- a/src/core/command/module-handler.ts +++ b/src/core/command/module-handler.ts @@ -237,6 +237,9 @@ export class CommandConfig { } private printBetaNoticeIfBetaOptions(): void { + if (this.isBetaCommand) { + return; + } for (const option of this.cmd.options) { if ((option as any).isBeta) { logger.info(chalk.yellow(`The option '${option.long}' is in beta and may change in future releases.`)); From c333e08a5b56939479a15689a2bc0f03ac74028e Mon Sep 17 00:00:00 2001 From: zgjimhaziri Date: Fri, 1 Aug 2025 12:00:59 +0200 Subject: [PATCH 4/4] TA-4038: Remove unused redundant fields --- src/core/command/module-handler.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/command/module-handler.ts b/src/core/command/module-handler.ts index feb8d927..298de60a 100644 --- a/src/core/command/module-handler.ts +++ b/src/core/command/module-handler.ts @@ -155,8 +155,6 @@ export class Configurator { */ export class CommandConfig { private deprecationMessage: string; - private isBetaCommand: boolean = false; - private betaOptions: string[]; constructor( private cmd: Command, @@ -206,7 +204,6 @@ export class CommandConfig { } public beta(): CommandConfig { - this.isBetaCommand = true; (this.cmd as any).isBeta = true; return this; } @@ -231,13 +228,13 @@ export class CommandConfig { } private printBetaNoticeIfBetaCommand(): void { - if (this.isBetaCommand) { + if ((this.cmd as any).isBeta) { logger.info(chalk.yellow("This command is in beta and may change in future releases.")); } } private printBetaNoticeIfBetaOptions(): void { - if (this.isBetaCommand) { + if ((this.cmd as any).isBeta) { return; } for (const option of this.cmd.options) {