From 57e9467df9431b6ab528332d4df542905682d5ec Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 3 Oct 2023 13:44:50 -0500 Subject: [PATCH 01/10] Use clap errors for codegen config parsing --- bindgen-cli/options.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index b6ff059da2..c730245967 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -4,6 +4,7 @@ use bindgen::{ FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; +use clap::error; use clap::{CommandFactory, Parser}; use std::fs::File; use std::io::{self, Error, ErrorKind}; @@ -18,7 +19,9 @@ fn rust_target_help() -> String { ) } -fn parse_codegen_config(what_to_generate: &str) -> io::Result { +fn parse_codegen_config( + what_to_generate: &str, +) -> Result { let mut config = CodegenConfig::empty(); for what in what_to_generate.split(',') { match what { @@ -29,9 +32,9 @@ fn parse_codegen_config(what_to_generate: &str) -> io::Result { "constructors" => config.insert(CodegenConfig::CONSTRUCTORS), "destructors" => config.insert(CodegenConfig::DESTRUCTORS), otherwise => { - return Err(Error::new( - ErrorKind::Other, - format!("Unknown generate item: {}", otherwise), + return Err(error::Error::raw( + error::ErrorKind::InvalidValue, + format!("Unknown codegen item kind: {}", otherwise), )); } } From ef870ff8838a8042cb0fe641cd53e26d7bba22be Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 3 Oct 2023 13:51:39 -0500 Subject: [PATCH 02/10] Change header type from `Option` to `String` --- bindgen-cli/options.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index c730245967..d563325af7 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -51,7 +51,7 @@ fn parse_codegen_config( )] struct BindgenCommand { /// C or C++ header file. - header: Option, + header: String, /// Path to write depfile to. #[arg(long)] depfile: Option, @@ -545,11 +545,7 @@ where let mut builder = builder(); - if let Some(header) = header { - builder = builder.header(header); - } else { - return Err(Error::new(ErrorKind::Other, "Header not found")); - } + builder = builder.header(header); if let Some(rust_target) = rust_target { builder = builder.rust_target(rust_target); From 011c2ec225d7322054fbef6f2601fe7f17a5d45c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 3 Oct 2023 14:08:41 -0500 Subject: [PATCH 03/10] Enclose flag arguments in `<...>` --- bindgen-cli/options.rs | 106 ++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index d563325af7..2f390faa7d 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -46,7 +46,7 @@ fn parse_codegen_config( #[derive(Parser, Debug)] #[clap( about = "Generates Rust bindings from C/C++ headers.", - override_usage = "bindgen [FLAGS] [OPTIONS] [HEADER] -- [CLANG_ARGS]...", + override_usage = "bindgen
-- ...", trailing_var_arg = true )] struct BindgenCommand { @@ -55,61 +55,61 @@ struct BindgenCommand { /// Path to write depfile to. #[arg(long)] depfile: Option, - /// The default style of code used to generate enums. - #[arg(long, value_name = "VARIANT")] + /// The default