tiny-parse-argv
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -95,2 +95,3 @@ /* IMPORT */ | ||
const required = options.required || []; | ||
const requiredSet = new Set(required); | ||
const known = new Set([...booleans, ...strings, ...Object.keys(defaults)]); | ||
@@ -109,4 +110,6 @@ const onMissing = options.onMissing; | ||
if (isOverridable(parsed[key])) { // Maybe we are setting this option multiple times | ||
const value = (strings.has(key) ? '' : positive); | ||
setAliased(parsed, key, value, aliases); | ||
if (!strings.has(key) || !requiredSet.has(key)) { // String options shouldn't have an inferred value if they are required | ||
const value = (strings.has(key) ? '' : positive); | ||
setAliased(parsed, key, value, aliases); | ||
} | ||
} | ||
@@ -113,0 +116,0 @@ optionPrev = option; |
@@ -5,3 +5,3 @@ { | ||
"description": "A tiny function for parsing process.argv, a modern rewrite of a sensible subset of minimist.", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
@@ -168,2 +168,3 @@ | ||
const required = options.required || []; | ||
const requiredSet = new Set ( required ); | ||
const known = new Set ([ ...booleans, ...strings, ...Object.keys ( defaults ) ]); | ||
@@ -190,6 +191,10 @@ const onMissing = options.onMissing; | ||
const value = ( strings.has ( key ) ? '' : positive ); | ||
if ( !strings.has ( key ) || !requiredSet.has ( key ) ) { // String options shouldn't have an inferred value if they are required | ||
setAliased ( parsed, key, value, aliases ); | ||
const value = ( strings.has ( key ) ? '' : positive ); | ||
setAliased ( parsed, key, value, aliases ); | ||
} | ||
} | ||
@@ -196,0 +201,0 @@ |
@@ -86,2 +86,23 @@ | ||
it ( 'detects string flags with empty value as missing, when they are required', t => { //TODO: Maybe they should just never receive an empty value | ||
t.plan ( 2 ); | ||
parse ( t, { | ||
input: ['-s'], | ||
options: { | ||
string: ['s'], | ||
required: ['s'], | ||
onMissing ( flags ) { | ||
t.deepEqual ( flags, ['s'] ); | ||
} | ||
}, | ||
output: { | ||
_: [], | ||
'--': [] | ||
} | ||
}); | ||
}); | ||
// bool: https://github.com/minimistjs/minimist/blob/main/test/bool.js | ||
@@ -88,0 +109,0 @@ |
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
38923
1347