geckodriver: Incrementally improve the UI (#214)
authorAndreas Tolfsen <ato@mozilla.com>
Tue, 06 Sep 2016 13:01:42 +0100
changeset 407678 cb88e73b57d35fce734aba488118681f1a467b36
parent 407677 6bf42d202373e9e90b9c02ae1d6937b6082734b6
child 407679 56f959b9aec5fe316055a59b0435e225854760e0
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
geckodriver: Incrementally improve the UI (#214) * incrementally improve the ui Copying information is currently included in --help and this patch makes it only appear when --version is invoked. Futhermore, the error messages that are printed on invalid input are made consistent. Source-Repo: https://github.com/mozilla/geckodriver Source-Revision: 697f7f40f7ce50743729392cf2ebc33b763659f7 committer: jgraham <james@hoppipolla.co.uk>
testing/geckodriver/src/main.rs
--- a/testing/geckodriver/src/main.rs
+++ b/testing/geckodriver/src/main.rs
@@ -16,113 +16,116 @@ extern crate zip;
 
 use clap::{App, Arg};
 use marionette::{MarionetteHandler, LogLevel, MarionetteSettings, extension_routes};
 use std::borrow::ToOwned;
 use std::io::Write;
 use std::net::{SocketAddr, IpAddr};
 use std::path::PathBuf;
 use std::str::FromStr;
-use webdriver::server::start;
 
 macro_rules! try_opt {
     ($expr:expr, $err_type:expr, $err_msg:expr) => ({
         match $expr {
             Some(x) => x,
             None => return Err(WebDriverError::new($err_type, $err_msg))
         }
     })
 }
 
 mod marionette;
 
-lazy_static! {
-    pub static ref VERSION: String =
-        format!("{}\n\n{}", crate_version!(),
-"The source code of this program is available at
-https://github.com/mozilla/geckodriver.
-
-This program is subject to the terms of the Mozilla Public License 2.0.
-You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.");
-}
-
 type ProgramResult = std::result::Result<(), (ExitCode, String)>;
 
 enum ExitCode {
     Ok = 0,
     Usage = 64,
 }
 
 fn app<'a, 'b>() -> App<'a, 'b> {
-    App::new("geckodriver")
+    App::new(format!("geckodriver {}", crate_version!()))
         .about("WebDriver implementation for Firefox.")
-        .version(&**VERSION)
         .arg(Arg::with_name("webdriver_host")
              .long("host")
              .value_name("HOST")
              .help("Host ip to use for WebDriver server (default: 127.0.0.1)")
              .takes_value(true))
         .arg(Arg::with_name("webdriver_port")
              .short("p")
              .long("port")
              .value_name("PORT")
              .help("Port to use for WebDriver server (default: 4444)")
              .takes_value(true))
         .arg(Arg::with_name("binary")
              .short("b")
              .long("binary")
              .value_name("BINARY")
-             .help("Path to the Firefox binary, if no binary capability provided")
+             .help("Path to the Firefox binary")
              .takes_value(true))
         .arg(Arg::with_name("marionette_port")
              .long("marionette-port")
              .value_name("PORT")
-             .help("Port to use to connect to gecko (default: random free port)")
+             .help("Port to use to connect to Gecko (default: random free port)")
              .takes_value(true))
         .arg(Arg::with_name("connect_existing")
              .long("connect-existing")
              .requires("marionette_port")
              .help("Connect to an existing Firefox instance"))
         .arg(Arg::with_name("verbosity")
              .short("v")
              .multiple(true)
              .conflicts_with("log_level")
-             .help("Set the level of verbosity. Pass once for debug level logging and twice for trace level logging"))
+             .help("Log level verbosity (-v for debug and -vv for trace level)"))
         .arg(Arg::with_name("log_level")
              .long("log")
              .takes_value(true)
              .value_name("LEVEL")
              .possible_values(
                  &["fatal", "error", "warn", "info", "config", "debug", "trace"])
              .help("Set Gecko log level"))
+         .arg(Arg::with_name("version")
+             .short("V")
+             .long("version")
+             .help("Prints version and copying information"))
 }
 
 fn print_err(reason: &str) {
-    let _ = writeln!(&mut ::std::io::stderr(), "\n{}", reason);
+    let prog = std::env::args().next().unwrap_or("geckodriver".to_owned());
+    let _ = writeln!(&mut ::std::io::stderr(), "{}: error: {}", prog, reason);
 }
 
 fn run() -> ProgramResult {
     let matches = app().get_matches();
 
+    if matches.is_present("version") {
+        println!("geckodriver {}\n\n{}", crate_version!(),
+"The source code of this program is available at
+https://github.com/mozilla/geckodriver.
+
+This program is subject to the terms of the Mozilla Public License 2.0.
+You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.");
+        return Ok(())
+    }
+
     let host = matches.value_of("webdriver_host").unwrap_or("127.0.0.1");
     let port = match u16::from_str(matches.value_of("webdriver_port").unwrap_or("4444")) {
         Ok(x) => x,
-        Err(_) => return Err((ExitCode::Usage, "Invalid WebDriver port".to_owned())),
+        Err(_) => return Err((ExitCode::Usage, "invalid WebDriver port".to_owned())),
     };
     let addr = match IpAddr::from_str(host) {
         Ok(addr) => SocketAddr::new(addr, port),
         Err(_) => return Err((ExitCode::Usage, "invalid host address".to_owned())),
     };
 
     let binary = matches.value_of("binary").map(|x| PathBuf::from(x));
 
     let marionette_port = match matches.value_of("marionette_port") {
         Some(x) => match u16::from_str(x) {
             Ok(x) => Some(x),
-            Err(_) => return Err((ExitCode::Usage, "Invalid Marionette port".to_owned())),
+            Err(_) => return Err((ExitCode::Usage, "invalid Marionette port".to_owned())),
         },
         None => None
     };
 
     // overrides defaults in Gecko
     // which are info for optimised builds
     // and debug for debug builds
     let log_level =
@@ -138,17 +141,18 @@ fn run() -> ProgramResult {
 
     let settings = MarionetteSettings {
         port: marionette_port,
         binary: binary,
         connect_existing: matches.is_present("connect_existing"),
         log_level: log_level,
     };
 
-    start(addr, MarionetteHandler::new(settings), extension_routes());
+    let handler = MarionetteHandler::new(settings);
+    webdriver::server::start(addr, handler, extension_routes());
 
     Ok(())
 }
 
 fn main() {
     let _ = env_logger::init();
 
     let exit_code = match run() {