[GH-ISSUE #310] Expose clap's shell completion generation methods via CLI #162

Closed
opened 2026-03-02 23:45:06 +03:00 by kerem · 0 comments
Owner

Originally created by @ed9w2in6 on GitHub (Dec 4, 2023).
Original GitHub issue: https://github.com/aome510/spotify-player/issues/310

Who, What, and Why

As a user,
I want shell completion,
so that I do not need to memorise the CLI or rely on the CLI's help utility.
--> This allows a smoother CLI usage experience and potentially further improves CLI discoverability.

Specific scenarios:

  • subcommand completion
    • there are a lot of subcommands, will be great to be able to search through them and list them all out temporarily with shell completions
  • option completion
    • same reasoning as above
  • argument completion
    • subcommands such as spotify_player get key <key> have arguments with specific values. Since they are nicely named but long, completion can speed this up by reducing risk of typo.

shell completion: custom TAB-completion available for some shells that requires custom script provided by the CLI program
some shells: clap_complete 4.4.4 provides bash, elvish, fish, powershell and zsh

How (roughly)

new dependencies

implementation directions

  1. provide subcommand that prints to stdout
    • The documentation above included an example implementation that prints completion script to stdout.
  2. generate at build time

When

NOT urgent.
The CLI is already very much usable at the current state.

Other informations

Originally created by @ed9w2in6 on GitHub (Dec 4, 2023). Original GitHub issue: https://github.com/aome510/spotify-player/issues/310 ## Who, What, and Why As a user, I want **shell completion**, so that I do not need to memorise the CLI or rely on the CLI's help utility. --> This allows a smoother CLI usage experience and potentially further improves CLI discoverability. Specific scenarios: + _subcommand_ completion - there are a lot of subcommands, will be great to be able to search through them and list them all out temporarily with shell completions + _option_ completion - same reasoning as above + _argument_ completion - subcommands such as `spotify_player get key <key>` have arguments with specific values. Since they are nicely named but long, completion can speed this up by reducing risk of typo. **shell completion**: custom TAB-completion available for **some shells** that requires custom script provided by the CLI program **some shells**: `clap_complete 4.4.4` provides `bash`, `elvish`, `fish`, `powershell` and `zsh` ## How (roughly) ### new dependencies + `clap_complete`: https://docs.rs/clap_complete/latest/clap_complete/index.html - `clap = "4.4.10"` requires `clap_complete`, our master branch is at `clap = "4.4.10"` as of [2023-12-04] ### implementation directions 1. provide subcommand that prints to stdout - The [documentation above](https://docs.rs/clap_complete/latest/clap_complete/index.html) included an example implementation that prints completion script to stdout. 2. generate at build time - The example for `generate_to` included an implementation that generates completions within the `build.rs` script during build time: https://docs.rs/clap_complete/latest/clap_complete/generator/fn.generate_to.html ## When NOT urgent. The CLI is already very much usable at the current state. ## Other informations + `spotify-tui` uses implementation direction 1, but they are using `clap = "2.33.3"`: https://github.com/Rigellute/spotify-tui/blob/c4dcf6b9fd8318017acbdd7ec005955e26cf2794/src/main.rs#L171-L185 + There was an issue with the said feature for `clap = "2.33.3"` BUT it _seems to be fixed_ since (`clap = "4.3.11"`, `clap_complete = "4.3.2"`): https://github.com/clap-rs/clap/issues/1822
kerem 2026-03-02 23:45:06 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-player#162
No description provided.