Skip to content
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
6 changes: 6 additions & 0 deletions src/content-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]");
Expand Down
19 changes: 19 additions & 0 deletions src/core/command/CustomHelp.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
34 changes: 33 additions & 1 deletion src/core/command/module-handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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";
import * as chalk from "chalk";

export abstract class IModule {
public abstract register(context: Context, commandConfig: Configurator): void;
Expand Down Expand Up @@ -185,6 +186,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;
Expand All @@ -195,9 +203,16 @@ export class CommandConfig {
return this;
}

public beta(): CommandConfig {
(this.cmd as any).isBeta = true;
Comment thread
ksalihu marked this conversation as resolved.
return this;
}

public action(handler: CommandHandler): void {
this.cmd.action(async (): Promise<void> => {
try {
this.printBetaNoticeIfBetaCommand();
this.printBetaNoticeIfBetaOptions();
this.printDeprecationNoticeIfDeprecated();
await handler(this.ctx, this.cmd, this.cmd.opts());
} catch (error) {
Expand All @@ -211,4 +226,21 @@ export class CommandConfig {
logger.warn("⚠️ [DEPRECATION NOTICE] \n" + this.deprecationMessage);
}
}

private printBetaNoticeIfBetaCommand(): void {
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.cmd as any).isBeta) {
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.`));
}
}
}
}