Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 90ac072

Browse files
authored
feat: support src/command/index cmd (#141)
1 parent 07bcfaa commit 90ac072

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {HelpBase} from '@oclif/plugin-help'
44
import {Command} from '.'
55
import {getHelpClass} from '@oclif/plugin-help'
66

7+
const ROOT_INDEX_CMD_ID = ''
8+
79
export class Main extends Command {
810
static run(argv = process.argv.slice(2), options?: Config.LoadOptions) {
911
return super.run(argv, options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname)
@@ -16,19 +18,23 @@ export class Main extends Command {
1618
}
1719

1820
async run() {
19-
const [id, ...argv] = this.argv
21+
let [id, ...argv] = this.argv
2022
this.parse({strict: false, '--': false, ...this.ctor as any})
2123
if (!this.config.findCommand(id)) {
2224
const topic = this.config.findTopic(id)
2325
if (topic) return this._help()
26+
if (this.config.findCommand(ROOT_INDEX_CMD_ID)) {
27+
id = ROOT_INDEX_CMD_ID
28+
argv = this.argv
29+
}
2430
}
2531
await this.config.runCommand(id, argv)
2632
}
2733

2834
protected _helpOverride(): boolean {
2935
if (['-v', '--version', 'version'].includes(this.argv[0])) return this._version() as any
3036
if (['-h', 'help'].includes(this.argv[0])) return true
31-
if (this.argv.length === 0) return true
37+
if (this.argv.length === 0 && !this.config.findCommand(ROOT_INDEX_CMD_ID)) return true
3238
for (const arg of this.argv) {
3339
if (arg === '--help') return true
3440
if (arg === '--') return false

0 commit comments

Comments
 (0)