Skip to content

Commit

Permalink
fix: cli no opts initial-url (#205)
Browse files Browse the repository at this point in the history
* fix: cli no opts initial-url

* chore: use url as opt
  • Loading branch information
pewsheen authored Oct 21, 2024
1 parent 26a609d commit 86baa1a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
let mut opts = getopts::Options::new();
opts.optopt("", "url", "URL to load on start", "URL");

let matches = opts.parse(&args[1..])?;
let initial_url = matches
.opt_str("initial-url")
.and_then(|initial_url| match url::Url::parse(&initial_url) {
let matches: getopts::Matches = opts.parse(&args[1..])?;
let url = matches
.opt_str("url")
.and_then(|url| match url::Url::parse(&url) {
Ok(url_parsed) => Some(url_parsed),
Err(e) => {
if e == url::ParseError::RelativeUrlWithoutBase {
if let Ok(url_parsed) = url::Url::parse(&format!("https://{initial_url}")) {
if let Ok(url_parsed) = url::Url::parse(&format!("https://{url}")) {
return Some(url_parsed);
}
}
log::error!("Invalid initial url: {initial_url}");
log::error!("Invalid initial url: {url}");
None
}
});

Ok(CliArgs { url: initial_url })
Ok(CliArgs { url })
}

impl Config {
Expand Down

0 comments on commit 86baa1a

Please sign in to comment.