Comparing version 6.1.1 to 6.1.2
@@ -139,2 +139,3 @@ "use strict"; | ||
.join('\n\n')); | ||
process.exit(0); | ||
} | ||
@@ -144,4 +145,4 @@ outputVersion(bin) { | ||
console.log(`${bin}/${this.versionNumber} ${process.platform}-${process.arch} node-${process.version}`); | ||
process.exit(0); | ||
} | ||
return this; | ||
} | ||
@@ -148,0 +149,0 @@ /** |
@@ -72,2 +72,3 @@ "use strict"; | ||
this.bin = argv[1] ? path_1.default.basename(argv[1]) : 'cli'; | ||
// Search sub-commands | ||
for (const command of this.commands) { | ||
@@ -79,16 +80,17 @@ const minimistOptions = utils_1.getMinimistOptions([ | ||
const { args, options, originalOptions } = this.minimist(argv.slice(2), minimistOptions); | ||
if (command.isMatched(args[0])) { | ||
const commandName = args[0]; | ||
if (command.isMatched(commandName)) { | ||
this.matchedCommand = command; | ||
this.args = args; | ||
this.args = args.slice(1); | ||
this.options = options; | ||
this.emit(`command:${args[0]}`, command); | ||
this.emit(`command:${commandName}`, command); | ||
this.runCommandAction(command, this.globalCommand, { | ||
args, | ||
args: this.args, | ||
options, | ||
originalOptions | ||
}); | ||
return { args, options }; | ||
return { args: this.args, options }; | ||
} | ||
} | ||
// Try the default command | ||
// Search the default command | ||
for (const command of this.commands) { | ||
@@ -154,9 +156,5 @@ if (command.name === '') { | ||
command.checkUnknownOptions(originalOptions, globalCommand); | ||
// The first one is command name | ||
if (!command.isDefaultCommand) { | ||
args = args.slice(1); | ||
} | ||
const minimalArgsCount = command.args.filter(arg => arg.required).length; | ||
if (args.length < minimalArgsCount) { | ||
console.error(`error: missing required args for command "${command.rawName}"`); | ||
if (command.args.length < minimalArgsCount) { | ||
console.error(`error: missing required args for command \`${command.rawName}\``); | ||
process.exit(1); | ||
@@ -163,0 +161,0 @@ } |
{ | ||
"name": "cac", | ||
"version": "6.1.1", | ||
"version": "6.1.2", | ||
"description": "Simple yet powerful framework for building command-line apps.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -61,3 +61,3 @@ import Option, { OptionConfig } from './Option'; | ||
outputHelp(config: HelpConfig): void; | ||
outputVersion(bin: string): this; | ||
outputVersion(bin: string): void; | ||
/** | ||
@@ -64,0 +64,0 @@ * Check if the parsed options contain any unknown options |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33022
589