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

Commit

Permalink
feat: support src/command/index cmd (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo authored Aug 3, 2020
1 parent 07bcfaa commit 90ac072
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -16,19 +18,23 @@ 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)
}

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
Expand Down

0 comments on commit 90ac072

Please sign in to comment.