diff --git a/src/main.ts b/src/main.ts index 2db52490..7c06163e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,8 @@ import {HelpBase} from '@oclif/plugin-help' import {Command} from '.' import {getHelpClass} from '@oclif/plugin-help' +const ROOT_INDEX_CMD_ID = '' + export class Main extends Command { static run(argv = process.argv.slice(2), options?: Config.LoadOptions) { return super.run(argv, options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) @@ -16,11 +18,15 @@ export class Main extends Command { } async run() { - const [id, ...argv] = this.argv + let [id, ...argv] = this.argv this.parse({strict: false, '--': false, ...this.ctor as any}) if (!this.config.findCommand(id)) { const topic = this.config.findTopic(id) if (topic) return this._help() + if (this.config.findCommand(ROOT_INDEX_CMD_ID)) { + id = ROOT_INDEX_CMD_ID + argv = this.argv + } } await this.config.runCommand(id, argv) } @@ -28,7 +34,7 @@ export class Main extends Command { protected _helpOverride(): boolean { if (['-v', '--version', 'version'].includes(this.argv[0])) return this._version() as any if (['-h', 'help'].includes(this.argv[0])) return true - if (this.argv.length === 0) return true + if (this.argv.length === 0 && !this.config.findCommand(ROOT_INDEX_CMD_ID)) return true for (const arg of this.argv) { if (arg === '--help') return true if (arg === '--') return false