-
Notifications
You must be signed in to change notification settings - Fork 717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clap your hands say yeah! 👏🏻 #228
Conversation
One thing that's weird about this is that Maybe just replace |
Some notes:
|
Probably a module annotated with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome! Thanks for doing this!
// clap doesn't support the end of options marker, -- | ||
// https://github.com/kbknapp/clap-rs/issues/735 | ||
let mut terminated = false; | ||
let (bindgen_args, clang_args): (Vec<_>, Vec<_>) = args.partition(|arg| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably if arg was a slice, it'd be easier to do something like postition()
, and then split_at
.
// https://github.com/kbknapp/clap-rs/issues/735 | ||
let mut terminated = false; | ||
let (bindgen_args, clang_args): (Vec<_>, Vec<_>) = args.partition(|arg| { | ||
if terminated { // clang arg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we simplify this as:
if arg == "--" {
terminated = true;
}
!terminated
Probably renaming terminated to in_clang_args
or something like that would also be neat.
|
||
let mut builder = builder(); | ||
|
||
if let Some(header) = matches.value_of("header") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of if let Some(..) { } else { }
, what do you think about:
let builder = match matches.value_of("header") {
Some(h) => builder.header(h),
None => return Err(..),
};
I don't feel too strongly about it, so feel free to leave as-is if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel weird about putting an early return in a match arm… going to leave this for now, but it's ultimately your call!
} | ||
|
||
// FIXME: hrrrmmm | ||
let _output = if let Some(path) = matches.value_of("output") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a helper, I guess this can return Result<Builder, Option<Box<io::Write>>
(I'd rather decide what to do with the missing output case in the caller).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I meant Result<(Builder, Option<Box<io::Write>), io::Error>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this, though realised that the output is not optional the way it works now -- it returns an io::Write
for a file or stdout. So that'll make it slightly simpler.
@@ -294,14 +66,20 @@ pub fn main() { | |||
} | |||
} | |||
|
|||
let (options, out) = parse_args_or_exit(bind_args); | |||
if let Ok(builder) = bindgen::builder_from_flags(env::args()) { | |||
//println!("{:#?}", builder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to go away before merging of course.
@@ -294,14 +66,20 @@ pub fn main() { | |||
} | |||
} | |||
|
|||
let (options, out) = parse_args_or_exit(bind_args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would remain something like:
let (options, out) = match bindgen::builder_from_flags(env::args()) {
Ok((builder, Some(out)) => (builder, out),
_ => // Exit, I guess.
};
aadd44f
to
11f91c8
Compare
Considering #204, can I put the command line parsing stuff in |
Probably as long as we keep it in the same repo it's fine. We can also |
Please ping when it's ready for review! :) |
Alrighty, it's review time! 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whohoo, looks great! I need to double check every flag is in the list, but with that and those two comments, this should be ready to go IMO.
Thanks for doing this 🎉
@@ -85,7 +85,7 @@ use regex_set::RegexSet; | |||
|
|||
use std::borrow::Borrow; | |||
use std::collections::HashSet; | |||
use std::fs::OpenOptions; | |||
use std::fs::{OpenOptions}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Revert?
bindings.write_dummy_uses() | ||
.expect("Unable to write dummy uses to file."); | ||
} | ||
Err(error) => println!("{}", error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We most likely want to exit with a nonzero error code here. Panicking may be ok, other kind of handling even better :)
Nits fixed. |
@bors-servo r+ Thanks! :) |
Trying to make bors hear me. |
@bors-servo r+ |
📌 Commit dc96c1f has been approved by |
Clap your hands say yeah! 👏🏻 In progress port to `clap`, obsoletes the `docopt` port in #202.
☀️ Test successful - status-travis |
In progress port to
clap
, obsoletes thedocopt
port in #202.