Closed antonmedv closed 7 years ago
What about using something as simple as:
/**
* Normalizes cli arguments list.
* Replaces `jsize react + react-dom`
* With `jsize react+react-dom`
*/
process.argv.forEach((arg, i, args) => {
if (arg === '+') {
const prev = args[i - 1]
const next = args[i + 1]
args.splice(i - 1, 3, prev + '+' + next)
}
})
Before passing the args to commander?
It's also pretty easily extended if we add support for other operations:
/**
* Normalizes cli arguments list.
* Replaces `jsize react + react-dom`
* With `jsize react+react-dom`
*/
process.argv.forEach((arg, i, args) => {
const prev = args[i - 1]
const next = args[i + 1]
switch (arg) {
case '+':
args.splice(i - 1, 3, prev + '+' + next)
break
case '-':
// Normalize to something else.
break
}
})
I think we can merge your PR first and then I'll rebase my PR.
My implementation allow any format:
jsize react+react-dom
jsize react + react-dom
jsize react+ react-dom
jsize react +react-dom +
(even incorrect)And it's simple bottom-up parsing algorithm. Can be easily extended.
To support this:
jsize react + react-dom