Skip to content

Commit

Permalink
Unbreak shell completion and --version without header
Browse files Browse the repository at this point in the history
This regressed again in rust-lang#2984. Partially revert d75fe27 and
42a86e2 and restore the previous behavior.

Fixes: rust-lang#3037
Fixes: rust-lang#3039
  • Loading branch information
heftig committed Dec 7, 2024
1 parent d3c489f commit 2e154e7
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions bindgen/options/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn parse_custom_attribute(
#[allow(clippy::doc_markdown)]
struct BindgenCommand {
/// C or C++ header file.
header: String,
header: Option<String>,
/// Path to write depfile to.
#[arg(long)]
depfile: Option<String>,
Expand Down Expand Up @@ -657,6 +657,33 @@ where
clang_args,
} = command;

if let Some(shell) = generate_shell_completions {
clap_complete::generate(
shell,
&mut BindgenCommand::command(),
"bindgen",
&mut io::stdout(),
);

exit(0)
}

if version {
println!(
"bindgen {}",
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")
);
if verbose {
println!("Clang: {}", crate::clang_version().full);
}

exit(0)
}

if header.is_none() {
return Err(io::Error::new(io::ErrorKind::Other, "Header not found"));
}

let mut builder = builder();

#[derive(Debug)]
Expand Down Expand Up @@ -804,31 +831,8 @@ where
}
}

let header = Some(header);

builder = apply_args!(
builder {
generate_shell_completions => |_, shell| {
clap_complete::generate(
shell,
&mut BindgenCommand::command(),
"bindgen",
&mut io::stdout(),
);

exit(0)
},
version => |_, _| {
println!(
"bindgen {}",
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")
);
if verbose {
println!("Clang: {}", crate::clang_version().full);
}

exit(0)
},
header,
rust_target,
rust_edition,
Expand Down

0 comments on commit 2e154e7

Please sign in to comment.