DEV Community

Lam
Lam

Posted on

3

Yargs Cheat Sheet

Methods

yargs.showHelp()
yargs.help() //=>string
Enter fullscreen mode Exit fullscreen mode

Reject non explicits

  .strict()
Enter fullscreen mode Exit fullscreen mode

Stacking

  .count('verbose')

argv.verbose // -vvv => 3
Enter fullscreen mode Exit fullscreen mode

Examples and more help stuff

  // more help
  .example('...')
  .epilog('copyright 2015')
  .command('start', 'start a server')
Enter fullscreen mode Exit fullscreen mode

Options

  .option('f', {
      alias : 'file',
      describe: 'x marks the spot',
      type: 'string', /* array | boolean | string */
      nargs: 1,
      demand: true,
      demand: 'file is required',
      default: '/etc/passwd'
      // also: count:true, requiresArg:true
  })

  .options({
    f: { ... }
  })
Enter fullscreen mode Exit fullscreen mode

Help and version

var argv = require('yargs')

  // version
  .alias('v', 'version')
  .version(function() { return require('../package').version; })
  .describe('v', 'show version information')

  // help text
  .alias('h', 'help')
  .help('help')
  .usage('Usage: $0 -x [num]')
  .showHelpOnFail(false, "Specify --help for available options")
Enter fullscreen mode Exit fullscreen mode

Basic usage

var argv = require('cs/yargs').argv;

argv._         // [ ... ]
argv.$0        // "node bin/mybin"
argv.verbose   // --verbose
Enter fullscreen mode Exit fullscreen mode

Reference

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more