clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
13.66k stars 1.02k forks source link

feat(clap-complete): implemented Generator for Clink autocompletions #5379

Open wabo225 opened 4 months ago

wabo225 commented 4 months ago

Basic implementation for #3159

After seeing that Clink wasn't included among the other Shells, I figured it wouldn't be too much trouble to add the basics of autocomplete. I'm privy to the complications brought up in #3166. Any semblance of safety seems to fly out of the window for this kind of cross language metaprogramming

Anyways I very nearly mirrored the implementation that the elvish generator uses, targeting the Lua script requirements for Clink to autocomplete.

I'll say I'm relatively new to open source contributions, so let me know if you have any feedback, or if I should dig a little deeper into this issue!

Context Quote from Issue #3159:

Describe your use case

While cmd.exe is not extensible out-of-the-box, there's a very popular framework known as Clink (which is used by the Cmder package) that adds Readline support along with history, completions, autosuggestions and highlighting. A set of handwritten completions are already available here https://github.com/vladimir-kotikov/clink-completions as an example.

As Clink does provide an official and extremely flexible API for writing completions, I feel this is something that Rust CLI programs can utilize through clap.

Describe the solution you'd like

I'm not very familiar with Rust itself, but similar to clap_generate/src/generators/shells/elvish.rs, we can have a clap_generate/src/generators/shells/cmd.rs source file too.

epage commented 4 months ago

3159 suggests this should start as a clap_complete_clink until we decide to officially promote this to being in clap_complete.

Would there also be a way for this to be integrated into completest so we can get end-to-end completion testing? This isn't a blocker but a nice to have.