Skip to content

Commit

Permalink
fix: cli completion binary name
Browse files Browse the repository at this point in the history
  • Loading branch information
hlhr202 committed Apr 17, 2024
1 parent b40c1dc commit 6ccc2fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions crates/openconnect-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ pub enum Commands {
Logs,

#[command(about = "Generate shell completion script")]
GenComplete { generator: Shell },
GenComplete {
generator: Shell,

/// The CLI binary name, default to 'openconnect', must be the same as the binary name used to run the CLI
#[arg(short = 'n', long, default_value = "openconnect")]
binary_name: Option<String>,
},
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -116,14 +122,14 @@ pub enum SeverConfigArgs {
},
}

pub fn print_completions(generator: Shell) {
pub fn print_completions(generator: Shell, binary_name: Option<String>) {
let mut cmd = Cli::command();
let cmd = &mut cmd;

generate(
generator,
cmd,
cmd.get_name().to_string(),
binary_name.unwrap_or(cmd.get_name().to_string()),
&mut std::io::stdout(),
);
}
7 changes: 5 additions & 2 deletions crates/openconnect-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ fn main() {
let cli = Cli::parse();

match cli.command {
Commands::GenComplete { generator } => {
crate::cli::print_completions(generator);
Commands::GenComplete {
generator,
binary_name,
} => {
crate::cli::print_completions(generator, binary_name);
}
Commands::Add(server_config) => {
crate::client::config::request_add_server(server_config);
Expand Down

0 comments on commit 6ccc2fd

Please sign in to comment.