cac
Advanced tools
Comparing version 6.3.10 to 6.3.11
@@ -282,2 +282,3 @@ 'use strict'; | ||
this.config = Object.assign({}, config); | ||
this.negated = false; | ||
this.names = utils.removeBrackets(rawName) | ||
@@ -292,3 +293,6 @@ .split(',') | ||
return name; | ||
}); | ||
}) | ||
.sort((a, b) => (a.length > b.length ? 1 : -1)); // Sort names | ||
// Use the longese name (last one) as actual option name | ||
this.name = this.names[this.names.length - 1]; | ||
if (this.negated) { | ||
@@ -475,2 +479,9 @@ this.config.default = true; | ||
} | ||
checkRequiredArgs() { | ||
const minimalArgsCount = this.args.filter(arg => arg.required).length; | ||
if (this.cli.args.length < minimalArgsCount) { | ||
console.error(`error: missing required args for command \`${this.rawName}\``); | ||
process.exit(1); | ||
} | ||
} | ||
/** | ||
@@ -501,6 +512,7 @@ * Check if the parsed options contain any unknown options | ||
for (const option of options) { | ||
const value = rawOptions[option.names[0].split('.')[0]]; | ||
const value = rawOptions[option.name.split('.')[0]]; | ||
// Check required option value | ||
if (option.required) { | ||
if (typeof value === 'boolean') { | ||
const hasNegated = this.options.some(o => o.negated && o.names.includes(option.name)); | ||
if (value === true || (value === false && !hasNegated)) { | ||
console.error(`error: option \`${option.rawName}\` value is missing`); | ||
@@ -745,7 +757,3 @@ process.exit(1); | ||
command.checkOptionValue(); | ||
const minimalArgsCount = command.args.filter(arg => arg.required).length; | ||
if (args.length < minimalArgsCount) { | ||
console.error(`error: missing required args for command \`${command.rawName}\``); | ||
process.exit(1); | ||
} | ||
command.checkRequiredArgs(); | ||
const actionArgs = []; | ||
@@ -752,0 +760,0 @@ command.args.forEach((arg, index) => { |
{ | ||
"name": "cac", | ||
"version": "6.3.10", | ||
"version": "6.3.11", | ||
"description": "Simple yet powerful framework for building command-line apps.", | ||
@@ -46,3 +46,5 @@ "repository": { | ||
}, | ||
"dependencies": {}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"release": { | ||
@@ -49,0 +51,0 @@ "branch": "master" |
@@ -62,2 +62,3 @@ import CAC from './CAC'; | ||
outputVersion(): void; | ||
checkRequiredArgs(): void; | ||
/** | ||
@@ -64,0 +65,0 @@ * Check if the parsed options contain any unknown options |
@@ -7,2 +7,5 @@ interface OptionConfig { | ||
description: string; | ||
/** Option name */ | ||
name: string; | ||
/** Option name and aliases */ | ||
names: string[]; | ||
@@ -12,5 +15,5 @@ isBoolean?: boolean; | ||
config: OptionConfig; | ||
negated?: boolean; | ||
negated: boolean; | ||
constructor(rawName: string, description: string, config?: OptionConfig); | ||
} | ||
export { OptionConfig }; |
46866
963