From 7bedad5eb4865c8b3c2264a06f52dd99af6b74dc Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 2 Feb 2018 00:34:57 -0800 Subject: [PATCH] feat: show default flag/arg values --- package.json | 12 ++++---- src/command.ts | 12 ++++++-- src/commands/help.ts | 2 +- test/command.test.ts | 27 +++++++++++++++++ test/commands/help.test.ts | 3 ++ yarn.lock | 59 ++++++++++++++++++++++++++------------ 6 files changed, 86 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index b1721fb8..cdc3d6be 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ }, "bugs": "https://github.com/anycli/plugin-help/issues", "dependencies": { - "@anycli/command": "^0.3.6", + "@anycli/command": "^0.3.7", "@anycli/screen": "^0.0.3", "chalk": "^2.3.0", - "cli-ux": "^3.3.12", + "cli-ux": "^3.3.13", "indent-string": "^3.2.0", "lodash": "^4.17.4", "string-width": "^2.1.1", @@ -24,10 +24,10 @@ "wrap-ansi": "^3.0.1" }, "devDependencies": { - "@anycli/config": "^0.2.11", - "@anycli/engine": "^0.1.47", - "@anycli/plugin-plugins": "^0.2.3", - "@anycli/plugin-version": "^0.1.19", + "@anycli/config": "^0.3.0", + "@anycli/engine": "^0.3.0", + "@anycli/plugin-plugins": "^0.2.4", + "@anycli/plugin-version": "^0.1.20", "@anycli/test": "^0.10.3", "@anycli/tslint": "^0.2.2", "@types/chai": "^4.1.2", diff --git a/src/command.ts b/src/command.ts index 7301cfd0..8eea61ab 100644 --- a/src/command.ts +++ b/src/command.ts @@ -50,7 +50,7 @@ export default class CommandHelp { '$', this.config.bin, command.id, - command.args.map(a => this.arg(a)).join(' '), + command.args.filter(a => !a.hidden).map(a => this.arg(a)).join(' '), flags.length && '[OPTIONS]', ]) .compact() @@ -75,11 +75,14 @@ export default class CommandHelp { } protected args(args: ICachedCommand['args']): Section | undefined { - if (!args.find(f => !!f.description)) return + if (!args.length) return return { heading: 'arguments', body: args.map(a => { - return [a.name!.toUpperCase(), a.description ? dim(a.description) : undefined] + const name = a.name.toUpperCase() + let description = a.description || '' + if (a.default) description = `[default: ${a.default}] ${description}` + return [name, description ? dim(description) : undefined] }) } } @@ -112,6 +115,9 @@ export default class CommandHelp { } let right = flag.description || '' + if (flag.type === 'option' && flag.default) { + right = `[default: ${flag.default}] ${right}` + } if (flag.required) right = `(required) ${right}` return [left, dim(right.trim())] diff --git a/src/commands/help.ts b/src/commands/help.ts index 9f75d67d..fdf4d833 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -13,7 +13,7 @@ export default class HelpCommand extends Command { format: flags.enum({description: 'output in a different format', options: ['markdown', 'man']}), } static args = [ - {name: 'command', required: false} + {name: 'command', required: false, description: 'command to show help for'} ] options = parse(this.argv, HelpCommand) diff --git a/test/command.test.ts b/test/command.test.ts index a5885bff..3472fa0e 100644 --- a/test/command.test.ts +++ b/test/command.test.ts @@ -156,6 +156,33 @@ ALIASES OPTIONS --myenum=(a|b|c)`)) + test + .commandHelp(class extends Command { + static id = 'apps:create' + static args = [ + {name: 'arg1', default: '.'}, + {name: 'arg2', default: '.', description: 'arg2 desc'}, + {name: 'arg3', description: 'arg3 desc'}, + ] + static flags = { + flag1: flags.string({default: '.'}), + flag2: flags.string({default: '.', description: 'flag2 desc'}), + flag3: flags.string({description: 'flag3 desc'}), + } + }) + .it('outputs with default options', ctx => expect(ctx.commandHelp).to.equal(`USAGE + $ anycli apps:create [ARG1] [ARG2] [ARG3] [OPTIONS] + +ARGUMENTS + ARG1 [default: .] + ARG2 [default: .] arg2 desc + ARG3 arg3 desc + +OPTIONS + --flag1=flag1 [default: .] + --flag2=flag2 [default: .] flag2 desc + --flag3=flag3 flag3 desc`)) + // class AppsCreate3 extends Command { // static id = 'apps:create' // static flags = { diff --git a/test/commands/help.test.ts b/test/commands/help.test.ts index cd14db80..5c8fb058 100644 --- a/test/commands/help.test.ts +++ b/test/commands/help.test.ts @@ -10,6 +10,9 @@ describe('help command', () => { USAGE $ anycli help [COMMAND] [OPTIONS] +ARGUMENTS + COMMAND command to show help for + OPTIONS --all see all commands in CLI --format=(markdown|man) output in a different format diff --git a/yarn.lock b/yarn.lock index dc6a0cf6..38384713 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,12 +2,12 @@ # yarn lockfile v1 -"@anycli/command@^0.3.4": - version "0.3.4" - resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.3.4.tgz#c02b07f0f309192021cd76fa66b3f88db173025e" +"@anycli/command@^0.3.5", "@anycli/command@^0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.3.7.tgz#293c366ed8227fcdc675e278a46d8f93435526a5" dependencies: "@anycli/parser" "^3.0.4" - cli-ux "^3.3.12" + cli-ux "^3.3.13" debug "^3.1.0" lodash "^4.17.4" tslib "^1.9.0" @@ -22,9 +22,9 @@ lodash "^4.17.4" tslib "^1.9.0" -"@anycli/config@^0.2.11": - version "0.2.11" - resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.11.tgz#1b043946b18e159e6e44195aa4fef309b79f8ede" +"@anycli/config@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.3.0.tgz#a0938488e7afc507d69ec13a8e52c71aaecc08ea" dependencies: cli-ux "^3.3.10" debug "^3.1.0" @@ -33,16 +33,17 @@ lodash "^4.17.4" read-pkg "^3.0.0" -"@anycli/engine@^0.1.47": - version "0.1.47" - resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.1.47.tgz#c266e74ed3d1f372065d6329c7a08be04be158ff" +"@anycli/engine@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.3.0.tgz#a021569b567dbc9abdc37d5e6630774f34b1cd56" dependencies: "@anycli/manifest-file" "^0.3.8" - cli-ux "^3.3.12" + cli-ux "^3.3.13" debug "^3.1.0" fs-extra "^5.0.0" globby "^7.1.1" lodash "^4.17.4" + semver "^5.5.0" "@anycli/manifest-file@^0.3.8": version "0.3.8" @@ -63,11 +64,11 @@ chalk "^2.3.0" lodash "^4.17.4" -"@anycli/plugin-plugins@^0.2.3": - version "0.2.3" - resolved "https://registry.yarnpkg.com/@anycli/plugin-plugins/-/plugin-plugins-0.2.3.tgz#75bd2ef541e87c0ce875f4b018cec6ed7cc9ebab" +"@anycli/plugin-plugins@^0.2.4": + version "0.2.4" + resolved "https://registry.yarnpkg.com/@anycli/plugin-plugins/-/plugin-plugins-0.2.4.tgz#894c837e74bc8116f816404fb8de99e440e5410a" dependencies: - "@anycli/command" "^0.3.4" + "@anycli/command" "^0.3.6" "@anycli/manifest-file" "^0.3.8" "@heroku-cli/color" "^1.1.3" chalk "^2.3.0" @@ -80,11 +81,11 @@ tslib "^1.9.0" yarn "^1.3.2" -"@anycli/plugin-version@^0.1.19": - version "0.1.19" - resolved "https://registry.yarnpkg.com/@anycli/plugin-version/-/plugin-version-0.1.19.tgz#8a4e9b3e44acb810cb1db82db71bf9dc1048b297" +"@anycli/plugin-version@^0.1.20": + version "0.1.20" + resolved "https://registry.yarnpkg.com/@anycli/plugin-version/-/plugin-version-0.1.20.tgz#c0b3bc5711d33bc7a71ef0264611165aab64ae3c" dependencies: - "@anycli/command" "^0.3.4" + "@anycli/command" "^0.3.5" cli-ux "^3.3.12" "@anycli/screen@^0.0.3": @@ -412,6 +413,26 @@ cli-ux@^3.3.12: strip-ansi "^4.0.0" supports-color "^5.1.0" +cli-ux@^3.3.13: + version "3.3.13" + resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.13.tgz#123e0c7a29d1f743447b919500a9055486992df6" + dependencies: + "@anycli/screen" "^0.0.3" + "@heroku/linewrap" "^1.0.0" + ansi-styles "^3.2.0" + cardinal "^1.0.0" + chalk "^2.3.0" + clean-stack "^1.3.0" + extract-stack "^1.0.0" + fs-extra "^5.0.0" + indent-string "^3.2.0" + lodash "^4.17.4" + node-notifier "^5.2.1" + password-prompt "^1.0.4" + semver "^5.5.0" + strip-ansi "^4.0.0" + supports-color "^5.1.0" + cli-width@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"