alias.js
This file
Path
examples/alias.js
37 lines · 970 bytes · JavaScript
Last changed by
Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738#!/usr/bin/env node
// This example shows giving alternative names for a command.
// const { Command } = require('commander'); // (normal include)const { Command } = require('../'); // include commander in git clone of commander repoconst program = new Command();
program .command('exec') .argument('<script>') .alias('ex') .action((script) => { console.log(`execute: ${script}`); });
program .command('print') .argument('<file>') // Multiple aliases is unusual but supported! You can call alias multiple times, // and/or add multiple aliases at once. Only the first alias is displayed in the help. .alias('p') .alias('pr') .aliases(['display', 'show']) .action((file) => { console.log(`print: ${file}`); });
program.parse();
// Try the following:// node alias.js --help// node alias.js exec script// node alias.js ex script// node alias.js print file// node alias.js pr file// node alias.js show file