cacjs/cac

Long hyphenated options aren't recognised as aliases

chocolateboy opened this issue · 0 comments

Issue Type

  • Bug Report

Keywords: options, alias, aliases, hyphen, kebab-case

Description

Long hyphenated options (e.g. --clear-screen) aren't recognised as aliases of short options (e.g. -c) or long non-hyphenated options (e.g. --clear).


Suppose you have a --clear-screen option (as in the README) which can also be called as --clear or -c:

cat ./test.js
const cli = require('cac')()
cli.option('-c, --clear, --clear-screen')
console.log(cli.parse().options)

If this command is called with -c or --clear (or --clearScreen), all three aliases are assigned the value, e.g.:

node ./test.js -c            # { '--': [], c: true, clear: true, clearScreen: true }
node ./test.js --clear       # { '--': [], c: true, clear: true, clearScreen: true }
node ./test.js --clearScreen # { '--': [], c: true, clear: true, clearScreen: true }

But if the command is called with the long hyphenated option, it's treated as an unknown option (the aliases are not assigned the value):

node ./test.js --clear-screen   # { '--': [], clearScreen: true }
node ./test.js --unknown-option # { '--': [], unknownOption: true }

Environment

CAC: 6.7.3
Node: v14.17.3
OS: Linux (Arch)