Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

feat: Add 'helpLabel' flag option #49

Merged
merged 4 commits into from
Apr 29, 2019
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
1 change: 1 addition & 0 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type IFlagBase<T, I> = {
name: string
char?: AlphabetLowercase | AlphabetUppercase
description?: string
helpLabel?: string
hidden?: boolean
required?: boolean
dependsOn?: string[],
Expand Down
9 changes: 7 additions & 2 deletions src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ const m = Deps()
export interface FlagUsageOptions { displayRequired?: boolean }
export function flagUsage(flag: IFlag<any>, 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()}` : ''

Expand Down
4 changes: 4 additions & 0 deletions test/help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
])
Expand Down