From fcf4d18fc1973b2d4edc0cd76e9450cfccb6404c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 17 Jan 2025 07:56:07 -0400 Subject: cli: more syntaxes for type: 'series' options --- src/util/cli.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/util/cli.js b/src/util/cli.js index 72979d3f..5d314dc4 100644 --- a/src/util/cli.js +++ b/src/util/cli.js @@ -95,8 +95,12 @@ export async function parseOptions(options, optionDescriptorMap) { // } // // ['--directory', 'apple'] -> {'directory': 'apple'} + // ['--directory=banana'] -> {'directory': 'banana'} // ['--directory', 'artichoke'] -> (error) + // // ['--files', 'a', 'b', 'c', ';'] -> {'files': ['a', 'b', 'c']} + // ['--files=a,b,c'] -> {'files': ['a', 'b', 'c']} + // ['--files', 'a,b,c'] -> {'files': ['a', 'b', 'c']} const handleDashless = optionDescriptorMap[parseOptions.handleDashless]; const handleUnknown = optionDescriptorMap[parseOptions.handleUnknown]; @@ -149,9 +153,27 @@ export async function parseOptions(options, optionDescriptorMap) { } case 'series': { + if (option.includes('=')) { + result[name] = option.split('=')[1].split(','); + break; + } + + // without a semicolon to conclude the series, + // assume the next option expresses the whole series if (!options.slice(i).includes(';')) { - console.error(`Expected a series of values concluding with ; (\\;) for --${name}`); - process.exit(1); + let value = options[++i]; + + if (!value || value.startsWith('-')) { + value = null; + } + + if (!value) { + console.error(`Expected values for --${name}`); + process.exit(1); + } + + result[name] = value.split('=')[1].split(','); + break; } const endIndex = i + options.slice(i).indexOf(';'); -- cgit 1.3.0-6-gf8a5