diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-01-17 07:56:07 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-01-17 07:56:07 -0400 |
commit | fcf4d18fc1973b2d4edc0cd76e9450cfccb6404c (patch) | |
tree | 3f671cb30e491c9b09acddcd0cb2123b64faac88 | |
parent | 38e4c4d60c411a19dbbf229bdece1833bb4eec1e (diff) |
cli: more syntaxes for type: 'series' options
-rw-r--r-- | src/util/cli.js | 26 |
1 files changed, 24 insertions, 2 deletions
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(';'); |