git » rust-bindgen.git » main » tree

[main] / 0001-Unbreak-shell-completion-and-version-without-header.patch

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
Date: Sat, 7 Dec 2024 18:54:51 +0100
Subject: [PATCH] Unbreak shell completion and --version without header

This regressed again in #2984. Partially revert d75fe271418e and
42a86e288c43 and restore the previous behavior.

Fixes: https://github.com/rust-lang/rust-bindgen/issues/3037
Fixes: https://github.com/rust-lang/rust-bindgen/issues/3039
---
 bindgen/options/cli.rs | 52 +++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs
index 9d5cea3dc653..8c4c05bc847d 100644
--- a/bindgen/options/cli.rs
+++ b/bindgen/options/cli.rs
@@ -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>,
@@ -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)]
@@ -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,