Skip to content

Commit 167f3f0

Browse files
authored
fix: unset matched command when --help or --version is present
1 parent af285e0 commit 167f3f0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/CAC.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ class CAC extends EventEmitter {
155155
}
156156
return this
157157
}
158+
159+
unsetMatchedCommand() {
160+
this.matchedCommand = undefined
161+
this.matchedCommandName = undefined
162+
}
158163

159164
/**
160165
* Parse argv
@@ -209,11 +214,13 @@ class CAC extends EventEmitter {
209214
if (this.options.help && this.showHelpOnExit) {
210215
this.outputHelp()
211216
run = false
217+
this.unsetMatchedCommand()
212218
}
213219

214220
if (this.options.version && this.showVersionOnExit) {
215221
this.outputVersion()
216222
run = false
223+
this.unsetMatchedCommand()
217224
}
218225

219226
const parsedArgv = { args: this.args, options: this.options }

0 commit comments

Comments
 (0)