Skip to content

Commit

Permalink
feat: Display flag option 'helpLabel' (#40)
Browse files Browse the repository at this point in the history
This feature replaces the flag label to the left of '=' with a new flag option
(helpLabel) when a value is supplied.
  • Loading branch information
childish-sambino authored and RasPhilCo committed Jun 1, 2019
1 parent dfa5e9d commit 5e9cd25
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Jeff Dickey @jdxcode",
"bugs": "https://github.com/oclif/plugin-help/issues",
"dependencies": {
"@oclif/command": "^1.5.8",
"@oclif/command": "^1.5.13",
"chalk": "^2.4.1",
"indent-string": "^3.2.0",
"lodash.template": "^4.4.0",
Expand All @@ -15,7 +15,7 @@
"wrap-ansi": "^4.0.0"
},
"devDependencies": {
"@oclif/config": "^1.12.0",
"@oclif/config": "^1.13.0",
"@oclif/dev-cli": "^1.21.0",
"@oclif/errors": "^1.2.2",
"@oclif/plugin-legacy": "^1.1.3",
Expand Down
21 changes: 13 additions & 8 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,21 @@ export default class CommandHelp {
protected flags(flags: Config.Command.Flag[]): string | undefined {
if (!flags.length) return
let body = renderList(flags.map(flag => {
const label = []
if (flag.char) label.push(`-${flag.char[0]}`)
if (flag.name) {
if (flag.type === 'boolean' && flag.allowNo) {
label.push(`--[no-]${flag.name.trim()}`)
} else {
label.push(`--${flag.name.trim()}`)
let left = flag.helpLabel

if (!left) {
const label = []
if (flag.char) label.push(`-${flag.char[0]}`)
if (flag.name) {
if (flag.type === 'boolean' && flag.allowNo) {
label.push(`--[no-]${flag.name.trim()}`)
} else {
label.push(`--${flag.name.trim()}`)
}
}
left = label.join(', ')
}
let left = label.join(', ')

if (flag.type === 'option') {
let value = flag.helpValue || flag.name
if (!flag.helpValue && flag.options) {
Expand Down
3 changes: 3 additions & 0 deletions test/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ multiline help`
force: flags.boolean({description: 'force it '.repeat(15)}),
ss: flags.boolean({description: 'newliney\n'.repeat(4)}),
remote: flags.string({char: 'r'}),
label: flags.string({char: 'l', helpLabel: '-l'}),
}})
.it('shows lots of output', ctx => expect(ctx.commandHelp).to.equal(`USAGE
$ oclif apps:create [APP_NAME]
Expand All @@ -52,6 +53,8 @@ OPTIONS
-f, --foo=foo foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo
barfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar
-l=label
-r, --remote=remote
--force force it force it force it force it force it force
Expand Down
31 changes: 29 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
supports-color "^5.4.0"
tslib "^1"

"@oclif/command@^1.5.1", "@oclif/command@^1.5.4", "@oclif/command@^1.5.6", "@oclif/command@^1.5.8":
"@oclif/command@^1.5.1", "@oclif/command@^1.5.4", "@oclif/command@^1.5.6":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.5.8.tgz#cd09d4f3183123548cb25d1b12b92e41277ac3e9"
integrity sha512-+Xuqp7by9jmB+GvR2r450wUXkCpZVdeOXQD0mLSEm3h+Mxhp0NPHuhzXZQvLI0/2fXR+cmJLv1CfpaCYaflL/g==
Expand All @@ -79,14 +79,32 @@
debug "^4.1.0"
semver "^5.6.0"

"@oclif/config@^1.10.2", "@oclif/config@^1.12.0":
"@oclif/command@^1.5.13":
version "1.5.13"
resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.5.13.tgz#7047f3e5c3abb8a08fb88ba3bf00ea96ea9a1d77"
integrity sha512-zkO8hRd5Sjl7a+GM9ZMNHLD8rneAPjFBFjkAwLPs/hEv72RnFeWSyW6eE1nDbKVzMyDUYmmWNQFp0lQuwhHCdA==
dependencies:
"@oclif/errors" "^1.2.2"
"@oclif/parser" "^3.7.3"
debug "^4.1.1"
semver "^5.6.0"

"@oclif/config@^1.10.2":
version "1.12.0"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.12.0.tgz#384c1502927d03581862ae3b68d8790b17590a7f"
integrity sha512-RB6A+N7Dq5DcFOQEhPpB8DdXtMQm2VDgdtgBKUdot815tj4gW7nDmRZBEwU85x4Xhep7Dx3tpaXobA6bFlSOWg==
dependencies:
debug "^4.1.1"
tslib "^1.9.3"

"@oclif/config@^1.13.0":
version "1.13.0"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.13.0.tgz#fc2bd82a9cb30a73faf7d2aa5ae937c719492bd1"
integrity sha512-ttb4l85q7SBx+WlUJY4A9eXLgv4i7hGDNGaXnY9fDKrYD7PBMwNOQ3Ssn2YT2yARAjyOxVE/5LfcwhQGq4kzqg==
dependencies:
debug "^4.1.1"
tslib "^1.9.3"

"@oclif/dev-cli@^1.21.0":
version "1.21.0"
resolved "https://registry.yarnpkg.com/@oclif/dev-cli/-/dev-cli-1.21.0.tgz#679fbf42b44129036a26b6b88ee867a6aaee5d87"
Expand Down Expand Up @@ -129,6 +147,15 @@
chalk "^2.4.1"
tslib "^1.9.3"

"@oclif/parser@^3.7.3":
version "3.8.0"
resolved "https://registry.yarnpkg.com/@oclif/parser/-/parser-3.8.0.tgz#397c73f92cf8ac82daa7448a916638a312775e3b"
integrity sha512-w1fCz0bpg1ukbYKLxQn3cYQS9hiqNgmFhlqAqqfr1k0ijMhA/g8Z+7mshiFs1w7OsxxnKhmRxPn7EZR4EJcemA==
dependencies:
"@oclif/linewrap" "^1.0.0"
chalk "^2.4.2"
tslib "^1.9.3"

"@oclif/plugin-help@^2.1.4":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-2.1.4.tgz#b530fa3147d5ae91ba9c84d085f53a829b2914dc"
Expand Down

0 comments on commit 5e9cd25

Please sign in to comment.