Skip to content
All essays
CraftApril 6, 202512 min

Modern CLI Frameworks: Oclif, Yargs, and Cac

Compare modern CLI frameworks. Learn Oclif, Yargs, Cac, and choose the right tool.

Ü
Ümit Uz
Mobile & Full Stack Developer

Oclif

typescript
import { 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

typescript
import 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.

Related essays

Next essay
Building CLI Tools with Node.js: Complete Guide