-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Usage() prints too much, how to get just one usage line? #1252
Comments
You can set a Usage template with |
Nice, almost there!
|
@cben Stumbled across the same problem. That's why https://github.com/cli/cli heavily worked around that. Would love to see an upcoming PR. Ping me if you need help. |
This issue is being marked as stale due to a long period of inactivity |
Seemed like there was some interest here but nothing ever moved forward. Going to leave stale tag but if someone wants to pick this up it seems like it would be well received. |
So after looking at this again and a peek at the code I think the solution is much more narrow for you to work around this. You had mentioned correctly that the help function relies heavily on what the usage string is. However, if there is a helpTemplate it will use that instead. You mentioned not wanting to copy the whole usage template because it was unwieldy. But you can grab the template first before reassigning it:
Going to close this; feel free to reopen if you feel there is more to discuss. |
Currently
Usage()
/UsageString()
is almost the same asHelp()
. As far as I can tell, it returns everything except theLong
description on top:Full example at https://play.golang.org/p/TLpJfHJ2fG5
I don't find this useful.
Yes, technically listing all flags is necessary to fully answer the question "how can I use this command". However, even the
Long
field usually contains relevant info! It explains what the command does, and AFAIK that's the only place we can currently stuff descriptions of positional args (#571). So if I wanted a full answer I'd useHelp()
.I want a compact message that's suitable to print on wrong invocations (especially wrong positional arguments). Something that's useful as a reminder; user can always --help for more details. In these cases I'd want:
I can get it now by peeking at
SubCmd.Use
but that's bad:[flags]
and cobra normalizes that when it prints usage.Backward compatibility
Re-defining Usage/UsageString now will I think do more harm than good.
But how do you feel of adding new method(s), e.g.
ShortUsageString
and optionallyShortUsage
?The text was updated successfully, but these errors were encountered: