meow ist ein leichtgewichtiger CLI-Helfer für Node.js, der Flags parst und saubere --help- und --version-Ausgaben erzeugt.
Grundlegende Einrichtung
const meow = require('meow');
const cli = meow(`
Usage:
$ mycli [input] [options]
Options:
--lang, -l Specify preferred language (default: en)
--verbose, -v Enable debug log output
--help, -h Show this help screen
--version Print version and exit
Examples:
$ mycli index.js --lang es
`, {
flags: {
lang: {
type: 'string',
shortFlag: 'l',
default: 'en'
},
verbose: {
type: 'boolean',
shortFlag: 'v'
}
}
});
Zugriff auf geparste Ausgaben
// Parsed flags (automatically normalized to camelCase)
console.log(cli.flags);
// => { lang: 'en', verbose: true }
// Positional non-flag arguments
console.log(cli.input);
// => ['index.js']
// Display help screen and exit
cli.showHelp();
Konfigurationsoptionen
| Option | Typ | Beschreibung |
|---|---|---|
flags |
Object | Zuordnung von Flagnamen und deren Typen (string, boolean, number) |
autoHelp |
Boolean | Automatisch --help abfangen (Standard: true) |
autoVersion |
Boolean | Automatisch --version abfangen (Standard: true) |
description |
String | Beschreibung aus package.json überschreiben |
allowUnknownFlags |
Boolean | Nicht im Schema definierte Flags zulassen |