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

POC supporting verbose descriptions for commands #1362

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

brandenrodgers
Copy link
Contributor

Description and Context

I was poking around Stripe's CLI and noticed they support multiple descriptions for commands. A short one that shows when the command is listed a a child of another command, and a longer one when you run the help command for a specific command. Our equivalent would be hs --help vs. hs auth --help. For the former, it's nice to provide a concise description because the list of commands is long and it's hard to parse if each command has a wordy description. For the latter, it would be ideal to give the user more detailed information.

Unfortunately, yargs doesn't make this easy out of the box, but I think I found a pretty clean solution that would let us provide both a short and long description for commands. This POC shows what it could look like for the hs auth command.

The addVerboseDescribe is pretty straightforward. It checks to see if the user included the --help flag, grabs the original help output, and then logs out a new one. I tried to make it safer by allowing it to safely throw. If it throws, the help output will just fall back to the default yargs behavior, which is to log out the command's describe export.

Screenshots

hs --help before

image

hs --help after

image

hs auth --help before

image

hs auth --help after

image (ignore the "undefined" in there. I just didn't pass in the config file constant to i18n)

TODO

Who to Notify

commands/auth.ts Outdated
@@ -227,6 +228,7 @@ exports.builder = yargs => {
},
});

await addVerboseDescribe(yargs, i18n(`${i18nKey}.verboseDescribe`));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't love that we have to make the builders async for this to work, but I couldn't find a way to get around it. yargs.showHelp() is async and we need it to grab the original help output for the command.

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.

1 participant