Skip to content
Myr

alias.cjs

This file

Path

examples/alias.cjs

36 lines · 865 bytes · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

lines 1–36why, one step back
1#!/usr/bin/env node
23// This example shows giving alternative names for a command.45const { Command } = require('commander');6const program = new Command();78program9 .command('exec')10 .argument('<script>')11 .alias('ex')12 .action((script) => {13 console.log(`execute: ${script}`);14 });1516program17 .command('print')18 .argument('<file>')19 // Multiple aliases is unusual but supported! You can call alias multiple times,20 // and/or add multiple aliases at once. Only the first alias is displayed in the help.21 .alias('p')22 .alias('pr')23 .aliases(['display', 'show'])24 .action((file) => {25 console.log(`print: ${file}`);26 });2728program.parse();2930// Try the following:31// node alias.cjs --help32// node alias.cjs exec script33// node alias.cjs ex script34// node alias.cjs print file35// node alias.cjs pr file36// node alias.cjs show file