Skip to content

Commit

Permalink
Fix shell completion generation
Browse files Browse the repository at this point in the history
Generating shell completions shouldn't require any Hive config.
Now `colmena gen-completions` gets included in the completions which
will be fixed later.
  • Loading branch information
zhaofengli committed Nov 5, 2023
1 parent 3538f18 commit 15a95d6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ pub async fn run() {
set_color_pref(&opts.color);
init_logging();

if let Command::GenCompletions { shell } = opts.command {
print_completions(shell, &mut Opts::command());
return;
}

let hive = get_hive(&opts).await.expect("Failed to get flake or hive");

use crate::troubleshooter::run_wrapped as r;
Expand Down Expand Up @@ -306,15 +311,19 @@ pub async fn run() {
};
r(command::apply::run(hive, args), opts.config).await
}
Command::GenCompletions { shell } => print_completions(shell, &mut Opts::command()),
Command::GenCompletions { .. } => unreachable!(),
}
}

fn print_completions(shell: Shell, cmd: &mut clap::Command) {
let bin_name = cmd.get_bin_name()
.expect("Must have a bin_name")
.to_string();

clap_complete::generate(
shell,
cmd,
cmd.get_name().to_string(),
bin_name,
&mut std::io::stdout(),
);
}
Expand Down

0 comments on commit 15a95d6

Please sign in to comment.