diff --git a/automation/capitanodoc/markdown.ts b/automation/capitanodoc/markdown.ts index 974d7b09..8c0df619 100644 --- a/automation/capitanodoc/markdown.ts +++ b/automation/capitanodoc/markdown.ts @@ -19,6 +19,7 @@ import * as ent from 'ent'; import * as _ from 'lodash'; import { getManualSortCompareFunction } from '../../lib/utils/helpers'; +import { capitanoizeOclifUsage } from '../../lib/utils/oclif-utils'; import { CapitanoCommand, Category, Document, OclifCommand } from './doc-types'; import * as utils from './utils'; @@ -106,7 +107,7 @@ function renderToc(categories: Category[]): string[] { const signature = typeof command === 'object' ? command.signature // Capitano - : utils.capitanoizeOclifUsage(command.usage); // oclif + : capitanoizeOclifUsage(command.usage); // oclif return `\t- [${ent.encode(signature)}](${getAnchor(signature)})`; }) .join('\n'), diff --git a/automation/capitanodoc/utils.ts b/automation/capitanodoc/utils.ts index 2eca5c7b..fe856a10 100644 --- a/automation/capitanodoc/utils.ts +++ b/automation/capitanodoc/utils.ts @@ -51,16 +51,6 @@ export function parseCapitanoOption(option: OptionDefinition): string { return ent.encode(result); } -/** Convert e.g. 'env add NAME [VALUE]' to 'env add <name> [value]' */ -export function capitanoizeOclifUsage( - oclifUsage: string | string[] | undefined, -): string { - return (oclifUsage || '') - .toString() - .replace(/(?<=\s)[A-Z]+(?=(\s|$))/g, match => `<${match}>`) - .toLowerCase(); -} - export class MarkdownFileParser { constructor(public mdFilePath: string) {} diff --git a/lib/actions/help_ts.ts b/lib/actions/help_ts.ts index d4d632ec..b9423bd0 100644 --- a/lib/actions/help_ts.ts +++ b/lib/actions/help_ts.ts @@ -20,6 +20,8 @@ import * as Bluebird from 'bluebird'; import * as _ from 'lodash'; import * as path from 'path'; +import { capitanoizeOclifUsage } from '../utils/oclif-utils'; + export async function getOclifHelpLinePairs(): Promise< Array<[string, string]> > { @@ -39,7 +41,7 @@ export async function getOclifHelpLinePairs(): Promise< function getCmdUsageDescriptionLinePair(cmdModule: any): [string, string] { const cmd: typeof Command = cmdModule.default; - const usage = (cmd.usage || '').toString().toLowerCase(); + const usage = capitanoizeOclifUsage(cmd.usage); let description = ''; // note: [^] matches any characters (including line breaks), achieving the // same effect as the 's' regex flag which is only supported by Node 9+ diff --git a/lib/utils/oclif-utils.ts b/lib/utils/oclif-utils.ts index b087aec7..e113573a 100644 --- a/lib/utils/oclif-utils.ts +++ b/lib/utils/oclif-utils.ts @@ -47,3 +47,13 @@ export class CommandHelp { return array.filter((a): a is T => !!a); } } + +/** Convert e.g. 'env add NAME [VALUE]' to 'env add <name> [value]' */ +export function capitanoizeOclifUsage( + oclifUsage: string | string[] | undefined, +): string { + return (oclifUsage || '') + .toString() + .replace(/(?<=\s)[A-Z]+(?=(\s|$))/g, match => `<${match}>`) + .toLowerCase(); +} diff --git a/tests/commands/help.spec.ts b/tests/commands/help.spec.ts index 4f8a0db8..fef2f584 100644 --- a/tests/commands/help.spec.ts +++ b/tests/commands/help.spec.ts @@ -58,9 +58,9 @@ Additional commands: device rm <uuid> remove a device device shutdown <uuid> shutdown a device devices supported list all supported devices - env add name [value] add an environment or config variable to an application or device - env rename id value change the value of an environment variable for an app or device - env rm id remove an environment variable from an application or device + env add <name> [value] add an environment or config variable to an application or device + env rename <id> <value> change the value of an environment variable for an app or device + env rm <id> remove an environment variable from an application or device envs list the environment or config variables of an app or device key <id> list a single ssh key key add <name> [path] add a SSH key to balena