Skip to content

Commit

Permalink
fix: hide underline if complex value
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 1, 2018
1 parent 469b95e commit 85ec92f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 32 deletions.
6 changes: 5 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
4 changes: 3 additions & 1 deletion src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,5 +30,6 @@ export default class HelpCommand extends Command {
let commandHelp = help.command(command)
cli.info(commandHelp)
}
if (format === 'screen') cli.info()
}
}
4 changes: 4 additions & 0 deletions test/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
23 changes: 23 additions & 0 deletions test/commands/help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`)
})
})
4 changes: 4 additions & 0 deletions test/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
4 changes: 4 additions & 0 deletions test/root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}))
Expand Down
39 changes: 9 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 85ec92f

Please sign in to comment.