Skip to content
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

Merged
merged 2 commits into from
Nov 10, 2016
Merged

Clap your hands say yeah! 👏🏻 #228

merged 2 commits into from
Nov 10, 2016

Conversation

jdub
Copy link
Contributor

@jdub jdub commented Nov 8, 2016

In progress port to clap, obsoletes the docopt port in #202.

@jdub
Copy link
Contributor Author

jdub commented Nov 8, 2016

One thing that's weird about this is that --output file name is parsed from the parameters, and most of Builder is private, so it can't be passed to Bindings::write(out: Box<io::Write>).

Maybe just replace write(Box<io::Write>) with write_to_output()?

@jdub
Copy link
Contributor Author

jdub commented Nov 8, 2016

Some notes:

  • I don't really want all of this stuck in libbindgen, but in bindgen and the libbindgen test harness, but it was easier to get started this way (maybe it should be a shared module… probably not a whole crate)
  • Instead of all that if damage, I should see if I can loop around the contents of matches

@emilio
Copy link
Contributor

emilio commented Nov 8, 2016

I don't really want all of this stuck in libbindgen, but in bindgen and the libbindgen test harness, but it was easier to get started this way (maybe it should be a shared module… probably not a whole crate)

Probably a module annotated with #[path=""] is not too hard?

Copy link
Contributor

@emilio emilio left a 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| {
Copy link
Contributor

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
Copy link
Contributor

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") {
Copy link
Contributor

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.

Copy link
Contributor Author

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") {
Copy link
Contributor

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).

Copy link
Contributor

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>

Copy link
Contributor Author

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);
Copy link
Contributor

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);
Copy link
Contributor

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.
};

@jdub jdub force-pushed the clap branch 2 times, most recently from aadd44f to 11f91c8 Compare November 9, 2016 05:47
@jdub
Copy link
Contributor Author

jdub commented Nov 9, 2016

Considering #204, can I put the command line parsing stuff in bindgen and use it with #[path=""] from the libbindgen test suite? Would files from bindgen even be present in a libbindgen crate?

@emilio
Copy link
Contributor

emilio commented Nov 9, 2016

Probably as long as we keep it in the same repo it's fine. We can also include! it at build time, I guess. We can figure that out when needed.

@emilio
Copy link
Contributor

emilio commented Nov 9, 2016

Please ping when it's ready for review! :)

@jdub
Copy link
Contributor Author

jdub commented Nov 9, 2016

Alrighty, it's review time! 😄

Copy link
Contributor

@emilio emilio left a 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};
Copy link
Contributor

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)
Copy link
Contributor

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 :)

@jdub
Copy link
Contributor Author

jdub commented Nov 10, 2016

Nits fixed.

@emilio
Copy link
Contributor

emilio commented Nov 10, 2016

@bors-servo r+

Thanks! :)

@emilio
Copy link
Contributor

emilio commented Nov 10, 2016

Trying to make bors hear me.

@emilio emilio closed this Nov 10, 2016
@emilio emilio reopened this Nov 10, 2016
@emilio
Copy link
Contributor

emilio commented Nov 10, 2016

@bors-servo r+

@bors-servo
Copy link

📌 Commit dc96c1f has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit dc96c1f with merge b3322dd...

bors-servo pushed a commit that referenced this pull request Nov 10, 2016
Clap your hands say yeah! 👏🏻

In progress port to `clap`, obsoletes the `docopt` port in #202.
@bors-servo
Copy link

☀️ Test successful - status-travis

@bors-servo bors-servo merged commit dc96c1f into rust-lang:master Nov 10, 2016
@jdub jdub deleted the clap branch November 10, 2016 11:27
@emilio emilio mentioned this pull request Nov 13, 2016
bors-servo pushed a commit that referenced this pull request Nov 14, 2016
bors-servo pushed a commit that referenced this pull request Nov 14, 2016
Fix path detection after #228

r? @fitzgen

Too bad we can't test it on CI because CI has the path correctly setup :(

Fixes #242
@jdub jdub mentioned this pull request Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants