meow est un assistant CLI léger pour Node.js qui analyse les drapeaux et affiche proprement --help et --version.
Configuration de base
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'
}
}
});
Accès au résultat analysé
// 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();
Options de configuration
| Option | Type | Description |
|---|---|---|
flags |
Object | Dictionnaire des drapeaux et de leurs types (string, boolean, number) |
autoHelp |
Boolean | Intercepter automatiquement --help (par défaut : true) |
autoVersion |
Boolean | Intercepter automatiquement --version (par défaut : true) |
description |
String | Remplacer la description du fichier package.json |
allowUnknownFlags |
Boolean | Autoriser les drapeaux non définis dans le schéma |