Skip to content

Commit

Permalink
[rust] Use optional arguments for CLI parsing in Selenium Manager (#1…
Browse files Browse the repository at this point in the history
…1421)

[rust] Use optional arguments CLI parsing for Selenium Manager
  • Loading branch information
bonigarcia authored Dec 13, 2022
1 parent c7488c6 commit 19ffbef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ Selenium Manager can be executed using Cargo as follows:

```
$ cargo run -- --help
selenium-manager 1.0.0-M1
Automated driver management for Selenium
selenium-manager 1.0.0-M2
Selenium Manager is a CLI tool that automatically manages the browser/driver infrastructure required by Selenium.
Usage: selenium-manager [OPTIONS]
Options:
-b, --browser <BROWSER>
Browser name (chrome, firefox, edge, or iexplorer) [default: ]
Browser name (chrome, firefox, edge, or iexplorer)
-d, --driver <DRIVER>
Driver name (chromedriver, geckodriver, msedgedriver, or IEDriverServer) [default: ]
Driver name (chromedriver, geckodriver, msedgedriver, or IEDriverServer)
-v, --driver-version <DRIVER_VERSION>
Driver version (e.g., 106.0.5249.61, 0.31.0, etc.) [default: ]
Driver version (e.g., 106.0.5249.61, 0.31.0, etc.)
-B, --browser-version <BROWSER_VERSION>
Major browser version (e.g., 105, 106, etc. Also: beta, dev, canary -or nightly- is accepted) [default: ]
Major browser version (e.g., 105, 106, etc. Also: beta, dev, canary -or nightly- is accepted)
-D, --debug
Display DEBUG messages
-T, --trace
Expand Down
24 changes: 12 additions & 12 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ use selenium_manager::{
{all-args}")]
struct Cli {
/// Browser name (chrome, firefox, edge, or iexplorer)
#[clap(short, long, value_parser, default_value = "")]
browser: String,
#[clap(short, long, value_parser)]
browser: Option<String>,

/// Driver name (chromedriver, geckodriver, msedgedriver, or IEDriverServer)
#[clap(short, long, value_parser, default_value = "")]
driver: String,
#[clap(short, long, value_parser)]
driver: Option<String>,

/// Driver version (e.g., 106.0.5249.61, 0.31.0, etc.)
#[clap(short = 'v', long, value_parser, default_value = "")]
driver_version: String,
#[clap(short = 'v', long, value_parser)]
driver_version: Option<String>,

/// Major browser version (e.g., 105, 106, etc. Also: beta, dev, canary -or nightly- is accepted)
#[clap(short = 'B', long, value_parser, default_value = "")]
browser_version: String,
#[clap(short = 'B', long, value_parser)]
browser_version: Option<String>,

/// Display DEBUG messages
#[clap(short = 'D', long)]
Expand All @@ -77,8 +77,8 @@ fn main() -> Result<(), Box<dyn Error>> {
clear_cache();
}

let browser_name: String = cli.browser;
let driver_name: String = cli.driver;
let browser_name: String = cli.browser.unwrap_or_default();
let driver_name: String = cli.driver.unwrap_or_default();

let mut selenium_manager: Box<dyn SeleniumManager> = if !browser_name.is_empty() {
get_manager_by_browser(browser_name).unwrap_or_else(|err| {
Expand All @@ -95,8 +95,8 @@ fn main() -> Result<(), Box<dyn Error>> {
exit(DATAERR);
};

selenium_manager.set_browser_version(cli.browser_version);
selenium_manager.set_driver_version(cli.driver_version);
selenium_manager.set_browser_version(cli.browser_version.unwrap_or_default());
selenium_manager.set_driver_version(cli.driver_version.unwrap_or_default());

match selenium_manager.resolve_driver() {
Ok(driver_path) => log::info!("{}", driver_path.display()),
Expand Down

0 comments on commit 19ffbef

Please sign in to comment.