1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-10-16 07:28:25 +02:00
cheatsheets/meow.md
Rico Sta. Cruz 511de900ba
Formatting updates (#2133)
- Update some sheets which have very long sections
- Remove `layout: 2017/sheet` (everything has the same layout now)
- Remove outdated sheets
2024-04-03 18:30:24 +11:00

1.1 KiB

title, category, updated, weight, intro
title category updated weight intro
Meow JavaScript libraries 2017-10-30 -1 [meow](https://npmjs.com/package/meow) is the easiest way to write command line apps for Node.js.

Typical settings

const cli = require('meow')(`
  Usage: appname [options]

  Options:
        --lang LANG    set the language

  Other options:
    -h, --help         show usage information
    -v, --version      print version info and exit
`, {
  string: ['lang'],
  boolean: ['help', 'version'],
  alias: { h: 'help', v: 'version' }
})

string and boolean lets meow/minimist know which flags expect arguments (string) and which don't (boolean).

Using the result

cli.flags   // { lang: 'en' }
cli.input   // []

Yes, flags are automatically camelCased!

Lesser-used settings

meow(`...`, {
  // Default values if flags are not specified
  default: { lang: 'en' },

  // allow using -- to stop processing flags
  '--': true,

  // Populate `_` with first non-option
  stopEarly: true,

  // Invoked on unknown param
  unknown: function () { ... }
})

Also see minimist.