Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign updelegate player example args parsing to clap #277
Conversation
|
I already have a patch for this but "forgot" it because I'm rewriting the player example. I should change that a push these things before duplicating work. |
| @@ -20,6 +20,10 @@ webrender = "0.58.0" | |||
| websocket = "0.22" | |||
| ipc-channel = "0.11" | |||
|
|
|||
| [dependencies.clap] | |||
| version = "2.33" | |||
| default-features = false | |||
This comment has been minimized.
This comment has been minimized.
ceyusa
Jul 8, 2019
Contributor
why are you disabling the default features?
I would just add clap = "2.33" in the dependencies section in alphabetic order.
This comment has been minimized.
This comment has been minimized.
khodzha
Jul 8, 2019
Author
Contributor
to be honest i was assuming you wouldnt want dependecies bloat and since these features arent critical i can just disable them
default features are suggestions (for typos), color for coloring errors and vecmap for a slight performance, you can see them here
This comment has been minimized.
This comment has been minimized.
ceyusa
Jul 10, 2019
Contributor
I saw the Cargo.lock diff and I got your point.
Though, as Captain Nitpick, I'd still change this to
[dependencies]
clap = { version = "2.33", default-features = false }
env_logger = "0.5"
| }; | ||
| let clap_matches = clap::App::new("Servo-media player example") | ||
| .setting(clap::AppSettings::DisableVersion) | ||
| .usage("player [--gl|--no-video] <FILE>") |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
khodzha
Jul 8, 2019
Author
Contributor
Maybe its my fault but the default usage string I got from clap here was:
<FILE> <--gl|--no-video> implying either of gl or no-video is required.
So this was the solution i went for.
Maybe it could be handled with args tuning but I couldn't find a way.
This comment has been minimized.
This comment has been minimized.
| .arg( | ||
| clap::Arg::with_name("gl") | ||
| .long("gl") | ||
| .display_order(1) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
khodzha
Jul 8, 2019
Author
Contributor
No, it just reorders them in help message, bringing default --help flag to the bottom, looked fancier to me.
This comment has been minimized.
This comment has been minimized.
| panic!("Usage: cargo run --bin player [--gl] <file_path>") | ||
| }; | ||
| let clap_matches = clap::App::new("Servo-media player example") | ||
| .setting(clap::AppSettings::DisableVersion) |
This comment has been minimized.
This comment has been minimized.
ceyusa
Jul 8, 2019
Contributor
nice!
Though I added
.author("Servo developers")
.about("Servo/MediaPlayer example using WebRender")
| clap::Arg::with_name("gl") | ||
| .long("gl") | ||
| .display_order(1) | ||
| .help("use opengl"), |
This comment has been minimized.
This comment has been minimized.
ceyusa
Jul 8, 2019
Contributor
In my version:
.help("Tries to render frames as GL textures")
.conflicts_with("NOVIDEO"),
The conflict_with is important.
| clap::Arg::with_name("no-video") | ||
| .long("no-video") | ||
| .display_order(2) | ||
| .help("dont render video"), |
This comment has been minimized.
This comment has been minimized.
| .value_name("FILE") | ||
| .display_order(3), | ||
| ) | ||
| .group(clap::ArgGroup::with_name("use_gl").args(&["gl", "no-video"])) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
khodzha
Jul 8, 2019
Author
Contributor
It's an alternative to .conflicts_with("NOVIDEO"), so I suppose its just a matter of preference
|
|
||
| let no_video = clap_matches.is_present("no-video"); | ||
| let use_gl = clap_matches.is_present("gl"); | ||
| let filename = clap_matches.value_of("file").unwrap(); |
This comment has been minimized.
This comment has been minimized.
ceyusa
Jul 8, 2019
Contributor
+ let path = matches
+ .value_of("FILE")
+ .and_then(|s| Some(Path::new(s)))
+ .unwrap();
- let path = Path::new(filename);
|
also sorry for kicking this from under you, i should've commented in the issue first |
98eb47e
to
41925cf
|
lgtm! |
|
@bors-servo r+ |
|
|
|
|
khodzha commentedJul 6, 2019
Issue #259.
I'm not sure if
--no-videoand--glhelp strings are valid though.