mirror of
https://github.com/anidl/multi-downloader-nx.git
synced 2026-01-11 20:10:20 +00:00
fix(args): transformer also applies to default values
This commit is contained in:
parent
429bb2d690
commit
aa1180df48
1 changed files with 5 additions and 3 deletions
|
|
@ -171,6 +171,8 @@ const appArgv = (
|
|||
process.exit(0);
|
||||
}
|
||||
|
||||
console.log(parsed as any);
|
||||
|
||||
argvC = parsed;
|
||||
return parsed;
|
||||
};
|
||||
|
|
@ -250,11 +252,13 @@ const getCommander = (cfg: Record<string, unknown>, isGUI: boolean) => {
|
|||
: `--${item.name}`) + (item.type === 'boolean' ? '' : ` <value>`),
|
||||
item.describe ?? ''
|
||||
);
|
||||
if (item.default !== undefined) option.default(item.default);
|
||||
if (item.default !== undefined) option.default(item.transformer ? item.transformer(item.default) : item.default);
|
||||
|
||||
const optionNames = [...args.map((a) => `--${a.name}`), ...args.map((a) => (a.alias ? `-${a.alias}` : null)).filter(Boolean)];
|
||||
|
||||
option.argParser((value) => {
|
||||
if (item.transformer) return item.transformer(value);
|
||||
|
||||
// Prevent from passing other options als value for option
|
||||
if (value && typeof value === 'string' && value.startsWith('-') && optionNames.includes(value)) return undefined;
|
||||
|
||||
|
|
@ -293,8 +297,6 @@ const getCommander = (cfg: Record<string, unknown>, isGUI: boolean) => {
|
|||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.transformer) return item.transformer(value);
|
||||
return value;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue