-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Display help text on empty subcommand by default #11953
Display help text on empty subcommand by default #11953
Conversation
Signed-off-by: Markus Thömmes <[email protected]>
/assign @rhatdan |
LGTM |
I'm on the fence on this one. I like the general idea, but the output from the help command is 50+ lines long, and if the user is on a 23 line terminal, it will just be
But that maybe a bit daunting too.... |
@markusthoemmes forgot to add, THX! for bringing this forward. |
We should probably do this on subcommands as well, what I don't like is scroll off the screen when you specify a bad option.
Git does a nice job at this. Docker does a better job then us on this also. Both Git and Docker stack the options at the top and the commands at the bottom, which is probably something we should consider. |
@rhatdan AFAIK this does work on subcommands as well 🤔 At least on everyone that's using the respective helper (at least your examples worked) |
I'll dig through the tests for a bit then 😅 |
If it does that would be good. |
If I understand the test I just changed correctly, it should actually check that. |
Signed-off-by: Markus Thömmes <[email protected]>
f02f349
to
184de39
Compare
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.
Thanks for the PR. Just one change to restore the original semantics.
cmd/podman/validate/args.go
Outdated
@@ -27,7 +27,7 @@ func SubCommandExists(cmd *cobra.Command, args []string) error { | |||
} | |||
return errors.Errorf("unrecognized command `%[1]s %[2]s`\n\nDid you mean this?\n\t%[3]s\n\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0], strings.Join(suggestions, "\n\t")) | |||
} | |||
return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath()) | |||
return cmd.Help() |
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.
I like the change, except for the semantics have changed where what was reported as an error now returns exit code 0. For backwards compatibility with existing scripts and to aid future script writers. Can we do something like:
return cmd.Help() | |
cmd.Help() | |
return errors.Errorf("missing command '%[1]s COMMAND", cmd.CommandPath() |
I'm wedded to that text, just the idea of keeping the old semantics
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.
Yes we still need to exit with nonzero.
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.
Good catch @jwhonce
159299f
to
af2278c
Compare
Signed-off-by: Markus Thömmes <[email protected]>
af2278c
to
756dda2
Compare
LGTM |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: markusthoemmes, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@jwhonce PTAL |
@mheon PTAL |
/lgtm |
What this PR does / why we need it:
This is a small quality-of-life improvement, where instead of guiding the user to use
--help
when they didn't enter a specific subcommand, it shows the help text by default.https://github.com/kubernetes/kubernetes/blob/efce40b931b5250498b9d8bcd67f987095ab6f74/hack/lib/util.sh#L714 in Kubernetes inspired me to do this. The
docker
CLI is behaving this way as well and Kubernetes uses this to check ifdocker buildx
exists. I suppose the K8s side could potentially change in this case as well, but I wanted to see if y'all think this is a worthwhile improvement for human users anyway.How to verify it
Run
podman
. It used to outputWith this it prints the help text immediately.
Which issue(s) this PR fixes:
None
Special notes for your reviewer:
I realize that this might be contentious in nature and I haven't found an issue relating to this. Please let me know if we should instead open an issue and discuss there first.