Skip to content

Long hyphenated options aren't recognised as aliases #119

Description

@chocolateboy

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions