Closed borekb closed 5 years ago
Nope, because help messages are arbitrary and it would inflate the source code. It's entirely out of scope IMO - @rauchg and I have discussed this before.
The way we do it is this:
const arg = require('arg');
const chalk = require('chalk');
const helpMessage = chalk`
{bold USAGE}
{dim $} {bold my-app} [--help] --string {underline some-arg}
{bold OPTIONS}
--help Shows this help message
--string {underline some-arg} A string flag
`;
const args = arg({
'--help': Boolean,
'--string': String
});
if (args['--help']) {
console.error(helpMessage);
process.exit(2);
}
console.log('you said:', args['--string']);
Took me about 2 minutes to write, tops.
@Qix- I was also wondering if args supported this feature. Maybe document as an FAQ in the readme that it’s out of scope (along with the code example, which is really nice)?
I'm looking for a package to help me write CLIs and very much like arg's simplicity for parsing args. I was thinking that if the spec format was a bit enhanced, it could perhaps help me print help as well, like this:
What do you think? I know it might be out of the scope of this package but arg parsing and printing help are closely related things and I'd like to stay DRY.