diff --git a/src/flags.ts b/src/flags.ts index 522c664..95e2846 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -8,6 +8,7 @@ export type IFlagBase = { name: string char?: AlphabetLowercase | AlphabetUppercase description?: string + helpLabel?: string hidden?: boolean required?: boolean dependsOn?: string[], diff --git a/src/help.ts b/src/help.ts index 563551a..cd78666 100644 --- a/src/help.ts +++ b/src/help.ts @@ -11,8 +11,13 @@ const m = Deps() export interface FlagUsageOptions { displayRequired?: boolean } export function flagUsage(flag: IFlag, options: FlagUsageOptions = {}): [string, string | undefined] { const label = [] - if (flag.char) label.push(`-${flag.char}`) - if (flag.name) label.push(` --${flag.name}`) + + if (flag.helpLabel) { + label.push(flag.helpLabel) + } else { + if (flag.char) label.push(`-${flag.char}`) + if (flag.name) label.push(` --${flag.name}`) + } const usage = flag.type === 'option' ? ` ${flag.name.toUpperCase()}` : '' diff --git a/test/help.test.ts b/test/help.test.ts index e23e15c..2cfc47b 100644 --- a/test/help.test.ts +++ b/test/help.test.ts @@ -13,10 +13,14 @@ describe('flagUsage', () => { flags.string({name: 'baz', description: 'baz'}), flags.string({name: 'bar', char: 'b', description: 'bar'}), flags.string({name: 'foo', char: 'f', description: 'desc'}), + flags.string({name: 'foo', char: 'f', helpLabel: '-f'}), + flags.boolean({char: 'g', description: 'goo'}), ] expect(flagUsages(f)).to.deep.equal([ [' -b, --bar BAR', 'bar'], [' -f, --foo FOO', 'desc'], + [' -f FOO', undefined], + [' -g', 'goo'], [' --bak BAK', undefined], [' --baz BAZ', 'baz'], ])