From c5741f6c09e9d668beaa000d8dc829ca1d95b034 Mon Sep 17 00:00:00 2001
From: Ryan Hunt <rhunt@eqrion.net>
Date: Wed, 24 May 2017 21:21:35 -0400
Subject: [PATCH] Try and infer the binding crate name

---
 src/main.rs | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 13efd15..7df04b0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -77,8 +77,23 @@ fn main() {
     }
 
     let library = if Path::new(&input).is_dir() {
-        let binding_crate = matches.value_of("crate")
-                                   .expect("--crate is required when building bindings for a library crate.");
+        let binding_crate = match matches.value_of("crate") {
+            Some(binding_crate) => binding_crate,
+            None => {
+                // Try and guess the root crate name by looking
+                // at the directory name, it would be better to
+                // look at the Cargo.toml for this
+                match Path::new(input).parent()
+                                      .and_then(|x| x.file_name())
+                                      .and_then(|x| x.to_str()) {
+                    Some(name) => name,
+                    None => {
+                        error!("cannot infer the name of the bindings crate. specify it with --crate");
+                        return;
+                    }
+                }
+            }
+        };
 
         Library::load_crate(Path::new(input), &binding_crate, &config)
     } else {
-- 
GitLab