Repository: versotile-org/verso
File: src/config.rs (Rust)

Code before:
};
use servo_config::opts::{default_opts, set_options, Opts};

/// Command line arguments.
#[derive(Clone, Debug, Default)]
pub struct CliArgs {
    /// Url to load initially.
    pub initial_url: Option<url::Url>,
}

/// Configuration of Verso instance.
#[derive(Clone, Debug)]
pub struct Config {
    /// Global flag options of Servo.
    pub opts: Opts,
    /// Path to resources directory.
    pub resource_dir: PathBuf,
    /// Command line arguments.
    pub cli_args: CliArgs,
}

fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
    let args: Vec<String> = std::env::args().collect();

    let mut opts = getopts::Options::new();
    opts.optopt("", "initial-url", "load this url 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) {
            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}")) {
                        return Some(url_parsed);
                    }
                }
                log::error!("Invalid initial url: {initial_url}");
                None
            }
        });

    Ok(CliArgs { initial_url })
}

impl Config {
    /// Create a new configuration for creating Verso instance. It must provide the path of
    /// resources directory.
    pub fn new(resource_dir: PathBuf) -> Self {
        let opts = default_opts();

Review comment (suggestion):
```suggestion
    opts.optopt("", "url", "URL to load on start", "URL");
```

Code after:
};
use servo_config::opts::{default_opts, set_options, Opts};

/// Command line arguments.
#[derive(Clone, Debug, Default)]
pub struct CliArgs {
    /// URL to load initially.
    pub url: Option<url::Url>,
}

/// Configuration of Verso instance.
#[derive(Clone, Debug)]
pub struct Config {
    /// Global flag options of Servo.
    pub opts: Opts,
    /// Path to resources directory.
    pub resource_dir: PathBuf,
    /// Command line arguments.
    pub args: CliArgs,
}

fn parse_cli_args() -> Result<CliArgs, getopts::Fail> {
    let args: Vec<String> = std::env::args().collect();

    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) {
            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}")) {
                        return Some(url_parsed);
                    }
                }
                log::error!("Invalid initial url: {initial_url}");
                None
            }
        });

    Ok(CliArgs { url: initial_url })
}

impl Config {
    /// Create a new configuration for creating Verso instance. It must provide the path of
    /// resources directory.
    pub fn new(resource_dir: PathBuf) -> Self {
        let opts = default_opts();