Skip to content

Commit 7e15320

Browse files
committed
multiple() args should only take 1 value
If multiple() args take more than 1 value, they'll consume positional arguments not intended to be values. This was causing `--raw-line "" header.h` to break option parsing. (Excluding cflags_args, which is for positional arguments after the end of options marker, `--`.)
1 parent 5e7849e commit 7e15320

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/lib.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub fn builder() -> Builder {
128128
pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::Error>
129129
where I: Iterator<Item=String>
130130
{
131-
let mmm = App::new("bindgen")
131+
let matches = App::new("bindgen")
132132
.version(env!("CARGO_PKG_VERSION"))
133133
.about("Generates Rust bindings from C/C++ headers.")
134134
.usage("bindgen [FLAGS] [OPTIONS] <header> -- <clang-args>...")
@@ -141,13 +141,15 @@ pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::E
141141
.help("Mark any enum whose name matches <regex> as a set of bitfield flags instead of an enumeration.")
142142
.value_name("regex")
143143
.takes_value(true)
144-
.multiple(true),
144+
.multiple(true)
145+
.number_of_values(1),
145146
Arg::with_name("blacklist-type")
146147
.long("blacklist-type")
147148
.help("Mark a type as hidden.")
148149
.value_name("type")
149150
.takes_value(true)
150-
.multiple(true),
151+
.multiple(true)
152+
.number_of_values(1),
151153
Arg::with_name("builtins")
152154
.long("builtins")
153155
.help("Output bindings for builtin definitions, e.g. __builtin_va_list."),
@@ -156,6 +158,7 @@ pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::E
156158
.help("Use the given prefix before raw types instead of ::std::os::raw.")
157159
.value_name("prefix")
158160
.takes_value(true),
161+
// All positional arguments after the end of options marker, `--`
159162
Arg::with_name("clang-args")
160163
.multiple(true),
161164
Arg::with_name("dummy-uses")
@@ -172,7 +175,8 @@ pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::E
172175
.long("framework-link")
173176
.help("Link to framework.")
174177
.takes_value(true)
175-
.multiple(true),
178+
.multiple(true)
179+
.number_of_values(1),
176180
Arg::with_name("ignore-functions")
177181
.long("ignore-functions")
178182
.help("Do not generate bindings for functions or methods. This is useful when you only care about struct layouts."),
@@ -184,7 +188,8 @@ pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::E
184188
.long("link")
185189
.help("Link to dynamic library.")
186190
.takes_value(true)
187-
.multiple(true),
191+
.multiple(true)
192+
.number_of_values(1),
188193
Arg::with_name("no-unstable-rust")
189194
.long("no-unstable-rust")
190195
.help("Do not generate unstable Rust code."),
@@ -193,7 +198,8 @@ pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::E
193198
.help("Mark a type as opaque.")
194199
.value_name("type")
195200
.takes_value(true)
196-
.multiple(true),
201+
.multiple(true)
202+
.number_of_values(1),
197203
Arg::with_name("output")
198204
.short("o")
199205
.long("output")
@@ -203,12 +209,14 @@ pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::E
203209
.long("raw-line")
204210
.help("Add a raw line of Rust code at the beginning of output.")
205211
.takes_value(true)
206-
.multiple(true),
212+
.multiple(true)
213+
.number_of_values(1),
207214
Arg::with_name("static")
208215
.long("static-link")
209216
.help("Link to static library.")
210217
.takes_value(true)
211-
.multiple(true),
218+
.multiple(true)
219+
.number_of_values(1),
212220
Arg::with_name("use-core")
213221
.long("use-core")
214222
.help("Use types from Rust core instead of std."),
@@ -220,28 +228,24 @@ pub fn builder_from_flags<I>(args: I) -> Result<(Builder, Box<io::Write>), io::E
220228
.help("Whitelist all the free-standing functions matching <regex>. Other non-whitelisted functions will not be generated.")
221229
.value_name("regex")
222230
.takes_value(true)
223-
.multiple(true),
231+
.multiple(true)
232+
.number_of_values(1),
224233
Arg::with_name("whitelist-type")
225234
.long("whitelist-type")
226235
.help("Whitelist the type. Other non-whitelisted types will not be generated.")
227236
.value_name("type")
228237
.takes_value(true)
229-
.multiple(true),
238+
.multiple(true)
239+
.number_of_values(1),
230240
Arg::with_name("whitelist-var")
231241
.long("whitelist-var")
232242
.help("Whitelist all the free-standing variables matching <regex>. Other non-whitelisted variables will not be generated.")
233243
.value_name("regex")
234244
.takes_value(true)
235-
.multiple(true),
245+
.multiple(true)
246+
.number_of_values(1),
236247
]) // .args()
237-
.get_matches_from_safe(args);
238-
239-
match mmm {
240-
Ok(ref m) => println!("{:#?}", m),
241-
Err(ref e) => println!("{:#?}", e)
242-
};
243-
244-
let matches = mmm.unwrap();
248+
.get_matches_from(args);
245249

246250
let mut builder = builder();
247251

0 commit comments

Comments
 (0)