Problems with dynamic completion #5677
-
I like the shell completion feature and now I want to add dynamic completion to the project Ankaios. For dynamic completion the CLI needs to request information from a server via gRPC. I saw the example for the My code looks like: let workloads = connection.complete_workloads().await.unwrap();
let my_completer = || workloads;
cmd = cmd.mut_subcommand("delete", |c1| {
c1.mut_subcommand("workload", |c2| {
c2.mut_arg("workload_name", |a| {
a.add(ArgValueCompleter::new(my_completer)) // does not work as my_completer is not a static closure
})
})
});
completions.complete(&mut cmd); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
This is a requirement of Note that we've recently shifted focus to For Cargo, we're running the bare amount of initialization each custom completer needs inside of itself. |
Beta Was this translation helpful? Give feedback.
This is a requirement of
clap
asclap::Command
andclap::Arg
do not have lifetimes. Adding them would be a breaking change and would have to wait for 5.0, if we decide to do it.Note that we've recently shifted focus to
clap_complete::CompleteEnv
which should run before the rest of your application initialization which precludes reusing initialization.For Cargo, we're running the bare amount of initialization each custom completer needs inside of itself.