2

I am using yargs to build a command line application with node.

One of my commands are as follows:

exports.command = 'website <type> <url> [prod]'
exports.aliases = ['w']
exports.desc =
  'create new website with type <type> at url <url> for production [prod]'
exports.builder = {}
exports.handler = function(argv) {

}

This works fine and I can run a command such as

website html https://example.com production

How can I give aliases to my optional or positional arguments, so that I can do something like this :

website --type html --url https://example.com --prod production

or even

website -t html -u https://example.com -p production

Also, when can I use double -- and when should I use single - . I have read the documentation here https://github.com/yargs/yargs/blob/master/docs/advanced.md but they don't go into detail on how to do this when using a modular command directory structure.

Please help

Janpan
  • 2,164
  • 3
  • 27
  • 53
  • I guess for now I will just use if statements to check if the arguments exist. – Janpan Feb 03 '20 at 10:48
  • In your case you have to support both versions, aliases are meant to shorthand writing not to avoid them, so you can eather make your arguments supports `--type|-t --url|-u --prod|p` or simply you pass directly the values as the beginning of the question. – H Aßdøµ Aug 22 '21 at 20:35

0 Answers0