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

Display help text on empty subcommand by default #11953

Merged
merged 3 commits into from
Nov 8, 2021

Conversation

markusthoemmes
Copy link
Contributor

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 if docker 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 output

Error: missing command 'podman COMMAND'
Try 'podman --help' for more information.

With 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.

@markusthoemmes
Copy link
Contributor Author

/assign @rhatdan

@rhatdan
Copy link
Member

rhatdan commented Oct 13, 2021

LGTM
Have to either add tests or add [NO NEW TESTS NEEDED] message to commit.

@TomSweeneyRedHat
Copy link
Member

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 Holy Scroll Batman! . I wonder if a new podman --shorthelp command might be good, with output like:

Error: missing command 'podman COMMAND'
Valid commands are: attach, auto-update, build, commit, container, cp, create, diff, events, exec, export, generate, healthcheck, help, history, image, images, import, info, init, inspect, kill, load, login, logout, logs, manifest, mount, network, pause, play, pod, port, ps, pull, push, rename, restart, rm, rmi, run, save, search, start, stats, stop, system, tag, top, umount, unpause, unshare, untag, version, volume, and wait.  Or try `podman --help` for more details.

But that maybe a bit daunting too....

@TomSweeneyRedHat
Copy link
Member

@markusthoemmes forgot to add, THX! for bringing this forward.

@rhatdan
Copy link
Member

rhatdan commented Oct 14, 2021

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.

 $ podman network
Error: missing command 'podman network COMMAND'
Try 'podman network --help' for more information.
$ podman container
Error: missing command 'podman container COMMAND'
Try 'podman container --help' for more information.

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.

@markusthoemmes
Copy link
Contributor Author

markusthoemmes commented Oct 14, 2021

@rhatdan AFAIK this does work on subcommands as well 🤔 At least on everyone that's using the respective helper (at least your examples worked)

@markusthoemmes
Copy link
Contributor Author

I'll dig through the tests for a bit then 😅

@rhatdan
Copy link
Member

rhatdan commented Oct 14, 2021

If it does that would be good.

@markusthoemmes
Copy link
Contributor Author

If I understand the test I just changed correctly, it should actually check that.

Copy link
Member

@jwhonce jwhonce left a 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.

@@ -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()
Copy link
Member

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:

Suggested change
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

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch @jwhonce

@markusthoemmes markusthoemmes force-pushed the help-default branch 4 times, most recently from 159299f to af2278c Compare November 4, 2021 18:21
Signed-off-by: Markus Thömmes <[email protected]>
@markusthoemmes
Copy link
Contributor Author

@rhatdan @jwhonce thanks for the feedback and sorry for taking a while to add it. This should be ready for another look now!

@rhatdan
Copy link
Member

rhatdan commented Nov 5, 2021

LGTM
/approve
Thanks @markusthoemmes

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 5, 2021

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 5, 2021
@rhatdan
Copy link
Member

rhatdan commented Nov 5, 2021

@jwhonce PTAL

@rhatdan
Copy link
Member

rhatdan commented Nov 6, 2021

@mheon PTAL

@markusthoemmes
Copy link
Contributor Author

/assign @jwhonce @mheon

@mheon
Copy link
Member

mheon commented Nov 8, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 8, 2021
@openshift-merge-robot openshift-merge-robot merged commit abfec81 into containers:main Nov 8, 2021
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants