Addition: flag.acceptsNaturalValue (default behavior unchanged)
This commit is contained in:
parent
5533706b30
commit
1b9b9e1312
11
index.js
11
index.js
@ -277,6 +277,11 @@ function validateAndFillDefaults(opts) {
|
|||||||
flagData.requiredValue = false;
|
flagData.requiredValue = false;
|
||||||
if(typeof flagData.requiredValue !== 'boolean')
|
if(typeof flagData.requiredValue !== 'boolean')
|
||||||
throw new TypeError(`flag["${flagName}"].requiredValue must be type boolean | undefined!`);
|
throw new TypeError(`flag["${flagName}"].requiredValue must be type boolean | undefined!`);
|
||||||
|
|
||||||
|
if(typeof flagData.acceptsNaturalValue === 'undefined')
|
||||||
|
flagData.acceptsNaturalValue = true;
|
||||||
|
if(typeof flagData.acceptsNaturalValue !== 'boolean')
|
||||||
|
throw new TypeError(`flag["${flagName}"].acceptsNaturalValue must be type boolean | undefined!`);
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -926,7 +931,8 @@ function parser(argv, opts) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
naturalFlagAssignment = { isLookingForValue: true, requiredType: flag.type };
|
if(flag.config === undefined || flag.config.acceptsNaturalValue)
|
||||||
|
naturalFlagAssignment = { isLookingForValue: true, requiredType: flag.type };
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -952,7 +958,8 @@ function parser(argv, opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags.push(flag);
|
flags.push(flag);
|
||||||
naturalFlagAssignment = { isLookingForValue: true, requiredType: flag.type };
|
if(flag.config === undefined || flag.config.acceptsNaturalValue)
|
||||||
|
naturalFlagAssignment = { isLookingForValue: true, requiredType: flag.type };
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
types.d.ts
vendored
4
types.d.ts
vendored
@ -5,8 +5,10 @@ interface FlagT<T, Z> {
|
|||||||
/** Shorhands, AKA only work with singular minus signs like -f; Multiple characters are allowed; Will not count as a full (like --f) flag alias; */
|
/** Shorhands, AKA only work with singular minus signs like -f; Multiple characters are allowed; Will not count as a full (like --f) flag alias; */
|
||||||
shorthands?: string|string[],
|
shorthands?: string|string[],
|
||||||
type?: Z
|
type?: Z
|
||||||
/** Whether to send/throw an error if the flag is present but no value is set, either with an assigned (--flag=value) value, or regular --flag value @default false */
|
/** If enabled, sends/throws an error if the flag is present but no value is set, either with an assigned value (ie: ["--flag=value"]), or natural value (ie: ["--flag", "value"]) @default false */
|
||||||
requiredValue?: boolean
|
requiredValue?: boolean
|
||||||
|
/** If disabled, only accepts assigned values (ie: ["--flag=value"]) for flag values (ie: the would-have-been value will instead become input) @default true*/
|
||||||
|
acceptsNaturalValue?: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FlagAny = FlagT<string, "string"> | FlagT<boolean, "boolean"> | FlagT<number, "number"> | FlagT<bigint, "bigint"> | FlagT<string | number | bigint | boolean, "any">
|
export type FlagAny = FlagT<string, "string"> | FlagT<boolean, "boolean"> | FlagT<number, "number"> | FlagT<bigint, "bigint"> | FlagT<string | number | bigint | boolean, "any">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user