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

cmd: add 'completion' command #158

Merged
merged 3 commits into from
Mar 21, 2024

Conversation

schilkp
Copy link
Contributor

@schilkp schilkp commented Mar 7, 2024

This PR adds a bender completion command that generates completion scripts for common shells (bash, zsh, fish, ...) using clap's clap_complete crate.

Example: https://asciinema.org/a/V3kPpxB7TCHRS1BJlRfYyhdPT

(Ignore the fact that the recording can't quite deal with unicode and screws up the shell prompt/command :)

It exposes all the shells supported by clap_complete:

  • bash
  • elvish
  • fish
  • powershell
  • zsh

I am not sure about benders compatibility with windows, it may make sense to remove powershell if it is anyway not supported.

Happy to rework this, if it is not quite fitting in its current state:)

@micprog micprog self-requested a review March 7, 2024 10:45
Copy link
Member

@micprog micprog left a comment

Choose a reason for hiding this comment

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

Other than the minor extension of the README, this LGTM. This feature is very cool, thanks a lot for the contribution!

README.md Outdated Show resolved Hide resolved
@schilkp
Copy link
Contributor Author

schilkp commented Mar 7, 2024

Can you add how to enable the completion for the different shells?

I think simply mentioning the script needs to be placed into a file and then sourced in the shell, preferably directly in the rc file, would suffice. This should avoid confusion by new users.

I have added a note that links to the relevant documentation for the most common shells. I don't know enough about different shells, and would worry that any specific advise is not universally correct :) It really depends not just on which shell you are using, but also how it is configured (things like oh-my-zsh/bash tend to mess with this sort of thing). Plus it seems like the kind of info that may become out-of-date quickly..

Let me know if you want more - but if so would probably be good if someone with a little more linux/unix/shell background does that.

On this note: I don't know if there is a "best practice" for submitting such completion scripts to any online repositories (such as https://github.com/zsh-users/zsh-completions), or if they would even accept an auto generated script like this. May be worth investigating.

Similarly I don't know if it would be appropriate/expected behavior for the init.sh script or Arch AUR PKGBUILD to include installation of these completion scripts? I would worry about that being a little brittle/causing problems, but really would improved the user experience.

@schilkp
Copy link
Contributor Author

schilkp commented Mar 7, 2024

I also noticed that the 'help'/'about' text for some subcommands/args is rather long. For example 'vendor':

longabout

Splitting those into a short 'about' and full 'long_about' 1 would make the completions much nicer.

Happy to do that (in here or a separate PR) if desired.

Footnotes

  1. https://docs.rs/clap/latest/clap/struct.Command.html#method.long_about

@schilkp
Copy link
Contributor Author

schilkp commented Mar 14, 2024

Long helps/abouts have been split. I don't know if there is a 'standard' for long help texts: Should they manually be split into lines (to say 80 cols) or should they be on one line and rely on terminal wrapping. At the moment I left them on one line, as they were before.

I also added a note the help text of bender and bender vendor that explains how to get to the help of a subcommand:

...
  init        Initialize a Bender package
  help        Print this message or the help of the given subcommand(s)

Options:
  -d, --dir <dir>  Sets a custom root working directory
      --local      Disables fetching of remotes (e.g. for air-gapped computers)
      --debug      Print additional debug information
  -h, --help       Print help
  -V, --version    Print version

Type 'bender <SUBCOMMAND> --help' for more infromation about a bender subcommand.

Copy link
Member

@micprog micprog left a comment

Choose a reason for hiding this comment

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

LGTM! Can you rebase on master? Then I will merge.

Add `bender completion` command that generates completion scripts
for common shells (bash, zsh, fish, ...) using clap's clap_complete
crate.
Split long helps/abouts into short and long version to cleanup
suggestions during autocomplete.
Adds a short note to the end of the help output of all commands
that take a subcommand, that directs users to the help text of those
subcommands.
@schilkp
Copy link
Contributor Author

schilkp commented Mar 21, 2024

@micprog done.

@micprog micprog merged commit 69c82e9 into pulp-platform:master Mar 21, 2024
6 checks passed
@schilkp schilkp deleted the schilkp/autocomplete branch March 21, 2024 13:14
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.

2 participants