Code Snippets

import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

const argv = yargs(hideBin(process.argv))
  .option('name',    { type: 'string', demandOption: true })
  .option('count',   { type: 'number', default: 1 })
  .option('verbose', { type: 'boolean', default: false })
  .parse();

for (let i = 0; i < argv.count; i++) {
  console.log(`Hello, ${argv.name}!`);
}