lean_ctx/cli/completions/
mod.rs1mod engine;
5mod shells;
6pub mod spec;
7
8pub fn run_completions(args: &[String]) {
10 let shell = args.first().map_or("zsh", String::as_str);
11 let script = match shell {
12 "zsh" => shells::zsh_script(),
13 "bash" => shells::bash_script(),
14 "fish" => shells::fish_script(),
15 other => {
16 eprintln!("Unknown shell: {other} (supported: zsh, bash, fish)");
17 std::process::exit(1);
18 }
19 };
20 print!("{script}");
21}
22
23#[allow(non_snake_case)]
25pub fn run___complete(args: &[String]) {
26 let (shell, words) = match args.iter().position(|a| a == "--") {
27 Some(pos) => {
28 let shell = args.first().map_or("zsh", String::as_str);
29 (shell, &args[pos + 1..])
30 }
31 None => ("zsh", args),
32 };
33
34 let completions = engine::complete(words);
35
36 let output = match shell {
37 "zsh" => shells::format_zsh(&completions),
38 "fish" => shells::format_fish(&completions),
39 _ => shells::format_bash(&completions),
40 };
41 print!("{output}");
42}