Skip to content
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

Closed

Conversation

matthewadams
Copy link

Automatically generate help for flags. Fixes #80.

@sindresorhus
Copy link
Owner

What is the behavior if the user specifies their own help text?

@sindresorhus
Copy link
Owner

Can you update the main readme example to use it? https://github.com/sindresorhus/meow#usage

it.desc
).join('\n'), 2);
}
}
Copy link
Owner

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];
Copy link
Owner

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: ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
desc: ''
description: ''


option.flag += o.alias ? `-${o.alias}, ` : ' '.repeat(4);
option.flag += `--${flag === '--' ? '' : flag}`;
accum.flagMaxLen = Math.max(accum.flagMaxLen, option.flag.length);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));
});
Copy link
Owner

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
Copy link
Owner

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
accum.valMaxLen = Math.max(accum.valMaxLen, option.value.length);
accum.valueMaxLength = Math.max(accum.valueMaxLength, option.value.length);

@sindresorhus
Copy link
Owner

Closing for lack of response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autogenerate flag help when no helpMessage is given
2 participants