Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions src/help/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ export class CommandHelp extends HelpFormatter {
right += colorize(this.config?.theme?.flagOptions, `\n<options: ${flag.options.join('|')}>`)
}

if (flag.dependsOn && flag.dependsOn.length > 0) {
right += colorize(this.config?.theme?.flagOptions, `\n<depends on: --${flag.dependsOn.join(', --')}>`)
}

if (flag.exclusive && flag.exclusive.length > 0) {
right += colorize(this.config?.theme?.flagOptions, `\n<exclusive with: --${flag.exclusive.join(', --')}>`)
}

return [left, colorize(this.config?.theme?.sectionDescription, right.trim())]
})
}
Expand Down
60 changes: 60 additions & 0 deletions test/help/format-command-with-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,64 @@ EXAMPLES
$ oclif oclif:command --help`)
})
})

describe('flag dependsOn and exclusive', () => {
it('should show dependsOn in flag help', async () => {
const cmd = await makeLoadable(
makeCommandClass({
flags: {
environment: flags.string({description: 'environment to deploy to'}),
config: flags.string({description: 'config file', dependsOn: ['environment']}),
},
id: 'apps:deploy',
}),
)
const output = help.formatCommand(cmd)
expect(output).to.include('<depends on: --environment>')
})

it('should show exclusive in flag help', async () => {
const cmd = await makeLoadable(
makeCommandClass({
flags: {
verbose: flags.boolean({description: 'verbose output'}),
quiet: flags.boolean({description: 'quiet output', exclusive: ['verbose']}),
},
id: 'apps:run',
}),
)
const output = help.formatCommand(cmd)
expect(output).to.include('<exclusive with: --verbose>')
})

it('should show multiple dependsOn flags', async () => {
const cmd = await makeLoadable(
makeCommandClass({
flags: {
environment: flags.string({description: 'environment'}),
region: flags.string({description: 'region'}),
config: flags.string({description: 'config file', dependsOn: ['environment', 'region']}),
},
id: 'apps:deploy',
}),
)
const output = help.formatCommand(cmd)
expect(output).to.include('<depends on: --environment, --region>')
})

it('should show multiple exclusive flags', async () => {
const cmd = await makeLoadable(
makeCommandClass({
flags: {
json: flags.boolean({description: 'output as json'}),
csv: flags.boolean({description: 'output as csv'}),
text: flags.boolean({description: 'output as text', exclusive: ['json', 'csv']}),
},
id: 'apps:list',
}),
)
const output = help.formatCommand(cmd)
expect(output).to.include('<exclusive with: --json, --csv>')
})
})
})