Skip to content

Commit

Permalink
always show global flags
Browse files Browse the repository at this point in the history
fixes #34
  • Loading branch information
Roy Razon committed Oct 26, 2023
1 parent a5a100b commit 7bb4ace
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
3 changes: 0 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@
"bin": "preevy",
"dirname": "preevy",
"commands": "./dist/commands",
"plugins": [
"@oclif/plugin-help"
],
"helpClass": "./dist/help",
"hooks": {
"init": [
Expand Down
25 changes: 25 additions & 0 deletions packages/cli/src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Args, Command, Flags } from '@oclif/core'
import Help from '../help'

export default class HelpCommand extends Command {
static args = {
commands: Args.string({description: 'Command to show help for.', required: false}),
}

static description = 'Display help for <%= config.bin %>.'

static flags = {
'nested-commands': Flags.boolean({
char: 'n',
description: 'Include all nested commands in the output.',
}),
}

static strict = false

async run(): Promise<void> {
const { argv, flags } = await this.parse(HelpCommand)
const help = new Help(this.config, { all: flags['nested-commands'] })
await help.showHelp(argv as string[])
}
}
44 changes: 40 additions & 4 deletions packages/cli/src/help.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import { Help as HelpBase } from '@oclif/core'
import { text } from '@preevy/cli-common'
import { CommandHelp as BaseCommandHelp, Help as OclifHelp } from '@oclif/core'
import { HelpOptions, Config, Topic } from '@oclif/core/lib/interfaces'
import { BaseCommand, text } from '@preevy/cli-common'

class GlobalFlagsHelp extends BaseCommandHelp {
constructor(config: Config, opts: HelpOptions) {
super(BaseCommand, config, opts)
}

globalFlags() {
const flags = Object.entries(BaseCommand.baseFlags).map(([name, value]) => ({ ...value, name }))
return this.flags(flags)
}
}

class CommandHelp extends BaseCommandHelp {
constructor(...args: ConstructorParameters<typeof BaseCommandHelp>) {
super(...args)
}
}

export default class Help extends OclifHelp {
constructor(...args: ConstructorParameters<typeof OclifHelp>) {
super(...args)
this.CommandHelpClass = CommandHelp
}

protected formatGlobalFlags(): string {
return this.section('GLOBAL FLAGS', new GlobalFlagsHelp(this.config, this.opts).globalFlags())
}

export default class Help extends HelpBase {
override async showRootHelp(): Promise<void> {
process.stderr.write('showRootHelp\n')
if (!this.opts.stripAnsi) {
this.log(text.logo)
}
return await super.showRootHelp()
await super.showRootHelp()
this.log(this.formatGlobalFlags())
this.log('')
}

override async showTopicHelp(topic: Topic): Promise<void> {
await super.showTopicHelp(topic)
this.log(this.formatGlobalFlags())
this.log('')
}
}

0 comments on commit 7bb4ace

Please sign in to comment.