-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #34
- Loading branch information
Roy Razon
committed
Oct 26, 2023
1 parent
a5a100b
commit 7bb4ace
Showing
3 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('') | ||
} | ||
} |