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

Commit 47be866

Browse files
committed
fix: run init before all multi commands
Fixes oclif/oclif#84
1 parent 3f25b1e commit 47be866

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
]
1212
},
1313
"dependencies": {
14-
"@oclif/errors": "^1.0.2",
14+
"@oclif/errors": "^1.0.3",
1515
"@oclif/parser": "^3.2.9",
1616
"debug": "^3.1.0",
1717
"semver": "^5.5.0"
1818
},
1919
"devDependencies": {
20-
"@oclif/config": "^1.3.60",
20+
"@oclif/config": "^1.3.61",
2121
"@oclif/plugin-help": "^1.2.1",
2222
"@oclif/plugin-plugins": "^1.0.8",
2323
"@oclif/tslint": "^1.0.2",

src/main.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ export class Main extends Command {
1313
return super.run(argv, options || module.parent && module.parent.parent && module.parent.parent.filename || __dirname)
1414
}
1515

16-
async run() {
16+
async init() {
1717
let [id, ...argv] = this.argv
1818
await this.config.runHook('init', {id, argv})
19+
await super.init()
20+
}
21+
22+
async run() {
23+
let [id, ...argv] = this.argv
1924
this.parse({strict: false, '--': false, ...this.ctor as any})
2025
if (!this.config.findCommand(id)) {
2126
let topic = this.config.findTopic(id)

test/main.test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {expect, fancy} from 'fancy-test'
2+
3+
import {Main} from '../src/main'
4+
5+
const pjson = require('../package.json')
6+
const version = `@oclif/command/${pjson.version} ${process.platform}-${process.arch} node-${process.version}`
7+
8+
describe('main', () => {
9+
fancy
10+
.stdout()
11+
.do(() => Main.run(['plugins']))
12+
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
13+
.it('runs plugins')
14+
15+
fancy
16+
.stdout()
17+
.do(() => Main.run(['-v']))
18+
.catch('EEXIT: 0')
19+
.do(output => expect(output.stdout).to.equal(version + '\n'))
20+
.it('runs -v')
21+
22+
fancy
23+
.stdout()
24+
.do(() => Main.run(['-h']))
25+
.catch('EEXIT: 0')
26+
.do(output => expect(output.stdout).to.equal(`oclif base command
27+
28+
VERSION
29+
${version}
30+
31+
USAGE
32+
$ @oclif/command [COMMAND]
33+
34+
COMMANDS
35+
help display help for @oclif/command
36+
plugins list installed plugins
37+
38+
`))
39+
.it('runs -h')
40+
})

yarn.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
debug "^3.1.0"
4141
semver "^5.5.0"
4242

43-
"@oclif/config@^1.3.60":
44-
version "1.3.60"
45-
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.3.60.tgz#e5e1b1cf14d68dd55c489bc5f76594073dec0568"
43+
"@oclif/config@^1.3.61":
44+
version "1.3.61"
45+
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.3.61.tgz#1d2293d1c78dc9d88e408afd35dea9a6dccecf84"
4646
dependencies:
4747
debug "^3.1.0"
4848

49-
"@oclif/errors@^1.0.2":
50-
version "1.0.2"
51-
resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.0.2.tgz#0a3f773d673a3ccd8dc26bf2e3c49580afcbe30e"
49+
"@oclif/errors@^1.0.2", "@oclif/errors@^1.0.3":
50+
version "1.0.3"
51+
resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.0.3.tgz#f23c024075855c7d116d041ee158f99bd51175af"
5252
dependencies:
5353
clean-stack "^1.3.0"
5454
fs-extra "^5.0.0"
@@ -448,14 +448,14 @@ [email protected]:
448448
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
449449

450450
http-call@^5.0.2:
451-
version "5.0.2"
452-
resolved "https://registry.yarnpkg.com/http-call/-/http-call-5.0.2.tgz#21bec3655f1631de128c0cdaa470777b1fbbc365"
451+
version "5.1.0"
452+
resolved "https://registry.yarnpkg.com/http-call/-/http-call-5.1.0.tgz#699847d9bcd635eb4e3fdfe3084456a9c89d716d"
453453
dependencies:
454454
content-type "^1.0.4"
455455
debug "^3.1.0"
456456
is-retry-allowed "^1.1.0"
457457
is-stream "^1.1.0"
458-
tslib "^1.8.1"
458+
tslib "^1.9.0"
459459
tunnel-agent "^0.6.0"
460460

461461
indent-string@^3.2.0:

0 commit comments

Comments
 (0)