Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command options should also show up when using --help #26

Merged
merged 6 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ export default class CommandHelp {
if (!args.filter(a => a.description).length) return
let body = renderList(args.map(a => {
const name = a.name.toUpperCase()
let options
if (a.options) {
options = `Can be one of: ${a.options.join(', ')}`
}
let description = a.description || ''
if (a.default) description = `[default: ${a.default}] ${description}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you instead do:

if (a.options) description = `(${a.options.join('|')}) ${description}`

This will better match how we show flag options.

Also, passing in a 3-length array to the list is likely not going to work in all cases. That behavior I plan to remove as we're not actually using it anyways I don't think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

return [name, description ? dim(description) : undefined]
return [name, description ? dim(description) : undefined, options]
}), {stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2})
return [
bold('ARGUMENTS'),
Expand Down
18 changes: 18 additions & 0 deletions src/commands/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Command} from '@oclif/command'

// import Help from '..'

export default class OptionsCommand extends Command {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would create a new command for all the CLIs which we definitely do not want. Inline the class like we do here: https://github.com/oclif/plugin-help/blob/master/test/command.test.ts#L116

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me now :D I updated the tests

static description = 'display options'

static args = [
{name: 'options', required: true, description: 'some options that should show', options: ['first', 'second']}
]
static strict = false

async run() {
// const {flags, argv} = this.parse(OptionsCommand)
// let help = new Help(this.config, {all: flags.all})
// help.showHelp(argv)
}
}
19 changes: 19 additions & 0 deletions test/commands/options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {expect, test} from '@oclif/test'

describe('help command', () => {
test
.stdout()
.command(['options'])
.skip()
.it('shows help command help', ctx => {
expect(ctx.stdout).to.equal(`display help for oclif

USAGE
$ oclif help [COMMAND]

ARGUMENTS
COMMAND some options that should show. Can be one of: first, second

`)
})
})