mirror of
https://github.com/anidl/multi-downloader-nx.git
synced 2026-01-11 20:10:20 +00:00
fix(args): correct parsing so string options don't treat the next option as a value
This commit is contained in:
parent
aed9169a69
commit
1bf0af08e6
1 changed files with 10 additions and 0 deletions
|
|
@ -252,7 +252,12 @@ const getCommander = (cfg: Record<string, unknown>, isGUI: boolean) => {
|
|||
);
|
||||
if (item.default !== undefined) option.default(item.default);
|
||||
|
||||
const optionNames = [...args.map((a) => `--${a.name}`), ...args.map((a) => (a.alias ? `-${a.alias}` : null)).filter(Boolean)];
|
||||
|
||||
option.argParser((value) => {
|
||||
// Prevent from passing other options als value for option
|
||||
if (value && typeof value === 'string' && value.startsWith('-') && optionNames.includes(value)) return undefined;
|
||||
|
||||
if (item.type === 'boolean') {
|
||||
if (value === undefined) return true;
|
||||
if (value === 'true') return true;
|
||||
|
|
@ -277,6 +282,11 @@ const getCommander = (cfg: Record<string, unknown>, isGUI: boolean) => {
|
|||
return Number.isFinite(num) ? num : 0;
|
||||
}
|
||||
|
||||
if (item.type === 'string') {
|
||||
if (value === undefined) return undefined;
|
||||
return value;
|
||||
}
|
||||
|
||||
if (item.choices && !(isGUI && item.name === 'service')) {
|
||||
if (!item.choices.includes(value)) {
|
||||
console.error(`Invalid value '${value}' for --${item.name}. Allowed: ${item.choices.join(', ')}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue