From cf3658b6ad303fab28fd7d902de08b3fab05087c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 18 Dec 2021 00:48:19 +0100 Subject: [PATCH] options: Implement --version manually and print clang version on --version --verbose Fixes #2138 --- src/options.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/options.rs b/src/options.rs index 081aad61da..4e1fb93fbe 100644 --- a/src/options.rs +++ b/src/options.rs @@ -23,13 +23,13 @@ where ); let matches = App::new("bindgen") - .version(option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")) .about("Generates Rust bindings from C/C++ headers.") + .setting(clap::AppSettings::NoAutoVersion) .override_usage("bindgen [FLAGS] [OPTIONS]
-- ...") .args(&[ Arg::new("header") .help("C or C++ header file") - .required(true), + .required_unless_present("V"), Arg::new("depfile") .long("depfile") .takes_value(true) @@ -545,9 +545,24 @@ where Arg::new("vtable-generation") .long("vtable-generation") .help("Enables generation of vtable functions."), + Arg::new("V") + .long("version") + .help("Prints the version, and exits"), ]) // .args() .get_matches_from(args); + let verbose = matches.is_present("verbose"); + if matches.is_present("V") { + println!( + "bindgen {}", + option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") + ); + if verbose { + println!("Clang: {}", crate::clang_version().full); + } + std::process::exit(0); + } + let mut builder = builder(); if let Some(header) = matches.value_of("header") { @@ -1015,7 +1030,5 @@ where builder = builder.vtable_generation(true); } - let verbose = matches.is_present("verbose"); - Ok((builder, output, verbose)) }