diff --git a/packages/cli/package.json b/packages/cli/package.json index e1ffa075..b8b82e34 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -65,9 +65,6 @@ "bin": "preevy", "dirname": "preevy", "commands": "./dist/commands", - "plugins": [ - "@oclif/plugin-help" - ], "helpClass": "./dist/help", "hooks": { "init": [ diff --git a/packages/cli/src/commands/help.ts b/packages/cli/src/commands/help.ts new file mode 100644 index 00000000..c560cc0d --- /dev/null +++ b/packages/cli/src/commands/help.ts @@ -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 { + const { argv, flags } = await this.parse(HelpCommand) + const help = new Help(this.config, { all: flags['nested-commands'] }) + await help.showHelp(argv as string[]) + } +} diff --git a/packages/cli/src/help.ts b/packages/cli/src/help.ts index 968e38fc..74e6e02a 100644 --- a/packages/cli/src/help.ts +++ b/packages/cli/src/help.ts @@ -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) { + super(...args) + } +} + +export default class Help extends OclifHelp { + constructor(...args: ConstructorParameters) { + 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 { + 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 { + await super.showTopicHelp(topic) + this.log(this.formatGlobalFlags()) + this.log('') } }