meow
meow copied to clipboard
Autogenerate flag help when no helpMessage is given
I'm coming from commander, which autogenerates documentation on flags, and was surprised to see that meow's autoHelp feature doesn't do the same.
// in index.js
const cli = require('meow')({
flags: {
'initial-indent': {
type: 'string',
alias: 'n',
description: 'Initial indentation level'
default: '0'
},
indent: {
type: 'string',
alias: 'i',
description: 'YAML indentation level'
default: '2'
}
}
})
cli.showHelp()
should generate output something like
$ ./index.js
My cool tool description
Options:
-n, --initial-indent [value] Initial indentation spaces. Optional; default 0.
-i, --indent [value] YAML indentation spaces. Optional; default 2.
Meow was initially just created to be a small helper lib for making tiny CLI's. It has now outgrown that, but it never had ambitions of being a Commander replacement.
I wouldn't mind having this though.
Can this be merged? Its a neat feature @sindresorhus?
https://github.com/sindresorhus/meow/pull/82 was closed as I got no response. If anyone wants to work on this, you can probably continue where that PR left off. Make sure to address the feedback given there.
I've created a new PR #140!
I'd love this as well. If not possible to completely auto-generate, maybe consider the option to have a helpMessage object instead of a string, like so:
const cli = meow({
description: 'A tool that does stuff with files and encodings',
inputs: ['<file>', '<encoding>'], // command name is auto-prepended based on process.argv
options: { // alternatively add the flag description to the flags object and make this property a boolean switch
'-c': 'Convert file encoding', // long option name auto-added based on flags object
'--dry-run': 'Output commands instead of executing', // option alias auto-added if available
'--help': 'Show this help message',
},
examples: {
'input.txt utf-8': 'Loads this file and converts to UTF-8', // command name is auto-prepended based on process.argv
'—dry-run other_file.csv': 'Outputs the file to stdout',
}
},
{
importMeta: import.meta,
flags: { … }
})