-
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #80: add autoHelpFlags #82
Conversation
What is the behavior if the user specifies their own |
Can you update the main readme example to use it? https://github.com/sindresorhus/meow#usage |
it.desc | ||
).join('\n'), 2); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved to a top-level function. For readability and maintainability purposes.
@@ -62,6 +63,64 @@ module.exports = (helpMessage, opts) => { | |||
|
|||
help = (description ? `\n ${description}\n` : '') + (help ? `\n${help}\n` : '\n'); | |||
|
|||
if (opts.autoHelpFlags && opts.flags) { | |||
const options = Object.keys(opts.flags).reduce((accum, flag) => { | |||
const o = opts.flags[flag]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use descriptive variable names.
const option = { | ||
flag: '', | ||
value: '', | ||
desc: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
desc: '' | |
description: '' |
|
||
option.flag += o.alias ? `-${o.alias}, ` : ' '.repeat(4); | ||
option.flag += `--${flag === '--' ? '' : flag}`; | ||
accum.flagMaxLen = Math.max(accum.flagMaxLen, option.flag.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accum.flagMaxLen = Math.max(accum.flagMaxLen, option.flag.length); | |
accum.flagMaxLength = Math.max(accum.flagMaxLength, option.flag.length); |
t.deepEqual(cli.flags['--'], ['unicorn', 'cake']); | ||
t.is(cli.pkg.name, 'meow'); | ||
t.is(cli.help, indentString('\nCLI app helper\n\n-u, --unicorn <value> Unicorn name\n --meow [<value>] What to meow; default dog\n -- arg(s) option/arg separator', 2)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature needs a lot more tests.
@@ -148,6 +150,13 @@ Default: `true` | |||
|
|||
Automatically show the version text when the `--version` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own version text. | |||
|
|||
##### autoHelpFlags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of this option name. Can you suggest some other alternatives?
} else { | ||
option.value = `${o.default ? '[' : ''}<value>${o.default ? ']' : ''}`; | ||
} | ||
accum.valMaxLen = Math.max(accum.valMaxLen, option.value.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accum.valMaxLen = Math.max(accum.valMaxLen, option.value.length); | |
accum.valueMaxLength = Math.max(accum.valueMaxLength, option.value.length); |
Closing for lack of response. |
Automatically generate help for flags. Fixes #80.