Runtime auto-completion, is there a viable way of doing it ? #2054
-
|
Hi there, Quite new to Rust, GitHub (created an account just for this) and CLIs in general, so I don't know of this is the best platform to speak about my issue, but here it goes. So far, I'm having a good time with clap-rs, I've been writing a small new CLI to get myself into Rust's waters so there is some frustration, but that's only because I'm new to the language. The one issue was not able to solve was auto-completion at runtime. I've used clap_generate to generate various shell auto-completion scripts, but it can only do basic stuff since all it can autocomplete with what's in the CLI's definition. At runtime, I would like to use the CLI with my-cli my-subcommand [Tab] where it would fill out items listed from an http request. I'm not sure if there is a way to programmatically of doing it since I don't have much experience writing CLIs, the only thing I know is that the application would feel much better if I could. I've played around (arg/mod/possible_values) and lazy_static crate to get those values at runtime, then regenerating my zsh auto-completion script, but it's not an elegant solution at all. Even if I were to create the file autocompletion file at runtime, move it to /usr/shared/zsh/site-functions, I would have to open a new terminal (probably a way to refresh it, but sill really wonky) to have possible_values listed with my command using possible_values's interface. So my question is, is there currently an easy way to programmatically auto complete at runtime in a clap CLI ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
No viable way for now, but we are working on it.
*quiet, dismal, and a bit neurotic laugh* So I thought. It wouldn't be too hard to implement something like this, but people got fancy and asked for a more sophisticated - and more handy, I admit - interface, which isn't so straightforward to meld into the current parser. The fact that the parsed is a monstrosity on its own doesn't help matters either. At any rate, you are very welcome to try. |
Beta Was this translation helpful? Give feedback.
No viable way for now, but we are working on it.
*quiet, dismal, and a bit neurotic laugh*
So I thought. It wouldn't be too hard to implement something like this, but people got fancy and asked for a more sophisticated - and more handy, I admit - interface, which isn't so straightforward to meld into the current parser. The fact that the parsed is a monstrosity on its own doesn't help matters either. At any rate, you are very welcome to try.