diff --git a/src/command.ts b/src/command.ts index 80e03f19..8b84a6f8 100644 --- a/src/command.ts +++ b/src/command.ts @@ -105,7 +105,11 @@ export default class CommandHelp { if (flag.char) label.push(blueBright(`-${flag.char[0]}`)) if (flag.name) label.push(blueBright(`--${flag.name.trim()}`)) let left = label.join(', ') - if (flag.type === 'option') left += `=${underline(flag.helpValue || flag.name)}` + if (flag.type === 'option') { + let value = flag.helpValue || flag.name + if (!value.includes('(')) value = underline(value) + left += `=${value}` + } let right = flag.description || '' if (flag.required) right = `(required) ${right}` diff --git a/src/commands/help.ts b/src/commands/help.ts index 8e390f50..9f75d67d 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -19,8 +19,9 @@ export default class HelpCommand extends Command { options = parse(this.argv, HelpCommand) async run() { + const format = this.options.flags.format as any || 'screen' let id = this.options.args.command - let help = new Help(this.config, {format: this.options.flags.format as any}) + let help = new Help(this.config, {format}) if (!id) { let rootHelp = help.root() cli.info(rootHelp) @@ -29,5 +30,6 @@ export default class HelpCommand extends Command { let commandHelp = help.command(command) cli.info(commandHelp) } + if (format === 'screen') cli.info() } } diff --git a/test/command.test.ts b/test/command.test.ts index 6a2a02e3..a5885bff 100644 --- a/test/command.test.ts +++ b/test/command.test.ts @@ -19,6 +19,10 @@ const test = base run(ctx: {help: Help, commandHelp: string, expectation: string}) { const cached = command!.convertToCached() let help = ctx.help.command(cached) + if (process.env.TEST_OUTPUT === '1') { + // tslint:disable-next-line + console.log(help) + } ctx.commandHelp = stripAnsi(help).split('\n').map(s => s.trimRight()).join('\n') ctx.expectation = 'has commandHelp' } diff --git a/test/commands/help.test.ts b/test/commands/help.test.ts index 59c07ea5..cd14db80 100644 --- a/test/commands/help.test.ts +++ b/test/commands/help.test.ts @@ -13,6 +13,29 @@ USAGE OPTIONS --all see all commands in CLI --format=(markdown|man) output in a different format + +`) + }) + + test + .stdout() + .command(['help']) + .it('shows root help', ctx => { + expect(ctx.stdout).to.equal(`standard help for anycli + +USAGE + $ anycli [COMMAND] + +DESCRIPTION + standard help for anycli + +COMMANDS + help display help for anycli + plugins + plugins:install + plugins:uninstall + version + `) }) }) diff --git a/test/markdown.test.ts b/test/markdown.test.ts index 9d8c399c..2af25c3f 100644 --- a/test/markdown.test.ts +++ b/test/markdown.test.ts @@ -17,6 +17,10 @@ const test = base run(ctx: {help: Help, commandHelp: string, expectation: string}) { const cached = command!.convertToCached() let help = ctx.help.command(cached) + if (process.env.TEST_OUTPUT === '1') { + // tslint:disable-next-line + console.log(help) + } ctx.commandHelp = stripAnsi(help).split('\n').map(s => s.trimRight()).join('\n') ctx.expectation = 'has commandHelp' } diff --git a/test/root.test.ts b/test/root.test.ts index 90b60f07..0c429752 100644 --- a/test/root.test.ts +++ b/test/root.test.ts @@ -10,6 +10,10 @@ const test = base .register('rootHelp', () => ({ run(ctx: {help: Help, commandHelp: string, expectation: string}) { let help = ctx.help.root() + if (process.env.TEST_OUTPUT === '1') { + // tslint:disable-next-line + console.log(help) + } ctx.commandHelp = stripAnsi(help).split('\n').map(s => s.trimRight()).join('\n') } })) diff --git a/yarn.lock b/yarn.lock index d050be12..99aedf09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,17 +2,7 @@ # yarn lockfile v1 -"@anycli/command@^0.2.19", "@anycli/command@^0.2.21": - version "0.2.21" - resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.2.21.tgz#68a725cddb0dece1d7dd69965de4ae7e3908b61c" - dependencies: - "@anycli/parser" "^3.0.1" - cli-ux "^3.3.10" - debug "^3.1.0" - lodash "^4.17.4" - tslib "^1.9.0" - -"@anycli/command@^0.2.22": +"@anycli/command@^0.2.19", "@anycli/command@^0.2.21", "@anycli/command@^0.2.22": version "0.2.22" resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.2.22.tgz#486b36d2916b28f08b9aedb129a758a4da2f542a" dependencies: @@ -22,18 +12,7 @@ lodash "^4.17.4" tslib "^1.9.0" -"@anycli/config@^0.2.3", "@anycli/config@^0.2.4": - version "0.2.4" - resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.4.tgz#957e4f174cadd397d9bdd81d3552544a8214273e" - dependencies: - cli-ux "^3.3.10" - debug "^3.1.0" - fs-extra "^5.0.0" - load-json-file "^4.0.0" - lodash "^4.17.4" - read-pkg "^3.0.0" - -"@anycli/config@^0.2.6": +"@anycli/config@^0.2.3", "@anycli/config@^0.2.4", "@anycli/config@^0.2.6": version "0.2.6" resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.6.tgz#d40709a61704907d4d6e7dcab6bbf124ab74e9ad" dependencies: @@ -65,7 +44,7 @@ lodash "^4.17.4" rwlockfile "^2.0.21" -"@anycli/parser@^3.0.1", "@anycli/parser@^3.0.2": +"@anycli/parser@^3.0.2": version "3.0.2" resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-3.0.2.tgz#69af00b6b6f0cc6da4405cf44dc29b2d14d30c6e" dependencies: @@ -1022,11 +1001,11 @@ extract-stack@^1.0.0: resolved "https://registry.yarnpkg.com/extract-stack/-/extract-stack-1.0.0.tgz#b97acaf9441eea2332529624b732fc5a1c8165fa" fancy-test@^0.6.4: - version "0.6.5" - resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.6.5.tgz#80a9dfb348fa34003ea030c3297bccc6ce825be2" + version "0.6.6" + resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.6.6.tgz#cda1afbf57ea2fb05291edbff34c0bbc2600d956" dependencies: lodash "^4.17.4" - stdout-stderr "^0.1.4" + stdout-stderr "^0.1.6" fast-deep-equal@^1.0.0: version "1.0.0" @@ -2253,9 +2232,9 @@ starts-with@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/starts-with/-/starts-with-1.0.2.tgz#16793a729d89d4cf3d4fb2eda2f908ae357f196f" -stdout-stderr@^0.1.4: - version "0.1.5" - resolved "https://registry.yarnpkg.com/stdout-stderr/-/stdout-stderr-0.1.5.tgz#adf87b96bb715b692fc62c727050d313ac832c23" +stdout-stderr@^0.1.6: + version "0.1.6" + resolved "https://registry.yarnpkg.com/stdout-stderr/-/stdout-stderr-0.1.6.tgz#82616602f639bf029c87ab1049b02640a39a18ba" dependencies: debug "*" strip-ansi "^4.0.0"