From 15a95d6de59b59df57fc1803817b0625118b45f9 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sun, 5 Nov 2023 01:00:05 -0700 Subject: [PATCH] Fix shell completion generation Generating shell completions shouldn't require any Hive config. Now `colmena gen-completions` gets included in the completions which will be fixed later. --- src/cli.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index bd33c2d..0854019 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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; @@ -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(), ); }