fix(args): correct parsing so string options don't treat the next option as a value

This commit is contained in:
stratumadev 2025-11-28 13:30:55 +01:00
parent aed9169a69
commit 1bf0af08e6

View file

@ -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(', ')}`);