Skip to content
Myr

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 file

Take it

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 1–37why, one step back
1#!/usr/bin/env node
23// This example shows giving alternative names for a command.45// const { Command } = require('commander'); // (normal include)6const { Command } = require('../'); // include commander in git clone of commander repo7const program = new Command();89program10 .command('exec')11 .argument('<script>')12 .alias('ex')13 .action((script) => {14 console.log(`execute: ${script}`);15 });1617program18 .command('print')19 .argument('<file>')20 // Multiple aliases is unusual but supported! You can call alias multiple times,21 // and/or add multiple aliases at once. Only the first alias is displayed in the help.22 .alias('p')23 .alias('pr')24 .aliases(['display', 'show'])25 .action((file) => {26 console.log(`print: ${file}`);27 });2829program.parse();3031// Try the following:32// node alias.js --help33// node alias.js exec script34// node alias.js ex script35// node alias.js print file36// node alias.js pr file37// node alias.js show file