The sound distributed version control system

#132 git-style command completion

Closed on February 22, 2023
loewenheim on November 28, 2020

In git, if you type e.g. git switch and hit Tab, you will get a list of all your branches. I don’t know how this kind of completion works, but it would be very nice to have.

arijid79 on November 29, 2020

This would have been a very nice addition. Although this cannot be currently implemented due to Clap not having an implementation of generating completions from structs. Though this is possible with the builder pattern

loewenheim on November 29, 2020

To be honest I don’t understand how clap would help here. At the time I want to see the completion, I’m still entering a line in the CLI, so the program hasn’t started yet.

arijid79 on November 29, 2020

A clap app has the function generate_completions to output auto completions for a specific shell into a file. This file is loaded by the shell to provide the completions. The problem with our implementation using structs is that it does not have such a method

loewenheim on November 29, 2020

No, I get that, but I don’t see how clap can generate completions for runtime information like what channels the current repo has.

danieleades on November 30, 2020


loewenheim on November 30, 2020

Wow, TIL. Thanks for the links!

pksunkara on November 30, 2020

Clap maintainer here, what’s the issue with generating completions from structs? Opts::into_app() should give you the built clap::App

arijid79 on November 30, 2020

Oh Thank you very much. I didn’t knew about the into_app() method

marians on December 3, 2020

So, what’s the way to go forward here? I would be willing to help with zsh completions.

pmeunier added tag Feature request on December 7, 2021
nbrr added a change on January 24, 2022
nbrr on January 24, 2022

Tried to see what clap_complete offers. The generated script only offers completion for commands/option names, this is as far as clap can go so far (see already mentioned above). I went for the runtime generation since it seems it would be necessary to split the cli building from the bin so that it can be used in the build script.

dbaynard on July 18, 2022

@nbrr I left a review — it would be nice to see your change merged!

pmeunier on February 22, 2023

I can’t believe it took me so long to review this. 2022 was a bit hectic for me, I hope to be back to normal now.

I just applied it to main. Thanks a lot for this patch.

pmeunier closed this discussion on February 22, 2023