Skip to content

Commit d9f049b

Browse files
heftigpvdrz
authored andcommitted
Unbreak shell completion and --version without header
This regressed again in #2984. Partially revert d75fe27 and 42a86e2 and restore the previous behavior. Fixes: #3037 Fixes: #3039
1 parent d3c489f commit d9f049b

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

bindgen/options/cli.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn parse_custom_attribute(
146146
#[allow(clippy::doc_markdown)]
147147
struct BindgenCommand {
148148
/// C or C++ header file.
149-
header: String,
149+
header: Option<String>,
150150
/// Path to write depfile to.
151151
#[arg(long)]
152152
depfile: Option<String>,
@@ -657,6 +657,33 @@ where
657657
clang_args,
658658
} = command;
659659

660+
if let Some(shell) = generate_shell_completions {
661+
clap_complete::generate(
662+
shell,
663+
&mut BindgenCommand::command(),
664+
"bindgen",
665+
&mut io::stdout(),
666+
);
667+
668+
exit(0)
669+
}
670+
671+
if version {
672+
println!(
673+
"bindgen {}",
674+
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")
675+
);
676+
if verbose {
677+
println!("Clang: {}", crate::clang_version().full);
678+
}
679+
680+
exit(0)
681+
}
682+
683+
if header.is_none() {
684+
return Err(io::Error::new(io::ErrorKind::Other, "Header not found"));
685+
}
686+
660687
let mut builder = builder();
661688

662689
#[derive(Debug)]
@@ -804,31 +831,8 @@ where
804831
}
805832
}
806833

807-
let header = Some(header);
808-
809834
builder = apply_args!(
810835
builder {
811-
generate_shell_completions => |_, shell| {
812-
clap_complete::generate(
813-
shell,
814-
&mut BindgenCommand::command(),
815-
"bindgen",
816-
&mut io::stdout(),
817-
);
818-
819-
exit(0)
820-
},
821-
version => |_, _| {
822-
println!(
823-
"bindgen {}",
824-
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")
825-
);
826-
if verbose {
827-
println!("Clang: {}", crate::clang_version().full);
828-
}
829-
830-
exit(0)
831-
},
832836
header,
833837
rust_target,
834838
rust_edition,

0 commit comments

Comments
 (0)