Menu

gitpiper

minimist Cheat Sheet in April 2024

Last Updated: 11 April 2024

README.md

Usage

var minimist = require('minimist')

{: .-setup}

var args = minimist(process.argv.slice(2), {
  string: 'lang',           // --lang xml
  boolean: ['version'],     // --version
  alias: { v: 'version' }
})
console.log(args)

All options are optional, but it’s recommended you set string and boolean at least.

All options

var args = minimist(process.argv.slice(2), {
  string: [ 'lang' ],
  boolean: [ 'pager' ],
  alias: { h: 'help', v: 'version' },
  default: { lang: 'en' },
  '--': true,
  stopEarly: true, /* populate _ with first non-option */
  unknown: function () { ... } /* invoked on unknown param */
})

All options are optional.

Result

With --lang xml --no-pager -h index.js package.json, you get:
{: .-setup}

args == {
  lang: 'xml',
  version: false,
  h: true,
  help: true,
  _: [ 'index.js', 'package.json' ]
}

Meow

Help and version

Use meow to automatically add support for --help, --version and more.
{: .-setup}

meow(`
    Usage:
        $0 FILES [options]

    Options:
        -h, --help         print usage information
        -v, --version      show version info and exit
`, {
  alias: { h: 'help', v: 'version' }
  /* minimist options */
})


338+ more cheat sheets for you in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️