Oclif
typescriptimport { Command, Flags } from '@oclif/core'; export default class Hello extends Command { static description = 'Say hello'; static flags = { name: Flags.string({ char: 'n', description: 'Name to greet' }) }; async run() { const { flags } = await this.parse(Hello); this.log(`Hello ${flags.name || 'World'}!`); } }
Yargs
typescriptimport yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; yargs(hideBin(process.argv)) .command('hello [name]', 'Say hello', (yargs) => { return yargs.positional('name', { describe: 'Name to greet', default: 'World' }); }, (argv) => { console.log(`Hello ${argv.name}!`); }) .parse();
Conclusion
Choose the right CLI framework for your needs.