Repository: servo/servo
File: ports/servoshell/prefs.rs (Rust)

Code before:
    if let Some(user_agent) = cmd_args.user_agent.clone() {
        preferences.user_agent = user_agent;
    }

    if cmd_args.webdriver_port.is_some() {
        preferences.dom_testing_html_input_element_select_files_enabled = true;
    }
}

pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsingResult {
    // Remove the binary name from the list of arguments.
    let args_without_binary = args
        .split_first()
        .expect("Expected executable name and arguments")
        .1;
    let cmd_args = cmd_args().run_inner(Args::from(args_without_binary));
    let cmd_args = match cmd_args {
        Ok(cmd_args) => cmd_args,
        Err(error) => {
            // Because this is very early in startup stdout/stderr forward
            // facilities might not be available yet
            if cfg!(target_os = "android") || cfg!(target_env = "ohos") {
                #[cfg(target_env = "ohos")]
                {
                    let mut builder = hilog::Builder::new();
                    builder.set_domain(hilog::LogDomain::new(0xE0C3));
                }
                #[cfg(target_os = "android")]
                {
                    android_logger::init_once(
                        Config::default()
                            .with_max_level(log::LevelFilter::Debug)
                            .with_filter(filter_builder.build())
                            .with_tag("servoshell"),
                    )
                }
                match &error {
                    ParseFailure::Stderr(doc) => log::error!("{doc}"),
                    _ => log::error!("This should never happen."),
                }
            } else {
                error.print_message(80);
            }

            return if error.exit_code() == 0 {
                ArgumentParsingResult::Exit
            } else {
                ArgumentParsingResult::ErrorParsing
            };
        },
    };

Review comment (suggestion):
This presumably has no effect without calling `builder.init()`.
It also looks like we initialize the hilog logger at the very beginning, so presumably we don't actually need to do anything here.

Code after:
    if let Some(user_agent) = cmd_args.user_agent.clone() {
        preferences.user_agent = user_agent;
    }

    if cmd_args.webdriver_port.is_some() {
        preferences.dom_testing_html_input_element_select_files_enabled = true;
    }
}

pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsingResult {
    // Remove the binary name from the list of arguments.
    let args_without_binary = args
        .split_first()
        .expect("Expected executable name and arguments")
        .1;
    let cmd_args = cmd_args().run_inner(Args::from(args_without_binary));
    let cmd_args = match cmd_args {
        Ok(cmd_args) => cmd_args,
        Err(error) => {
            // Servo will exit after printing the parsing error, which makes the stdout / stderr
            // redirection via a seperate thread racy, so we log directly to the system logger.
            if cfg!(target_os = "android") || cfg!(target_env = "ohos") {
                match &error {
                    ParseFailure::Stderr(doc) => log::error!("{doc}"),
                    // '--help' will be parsed by the next one.
                    ParseFailure::Stdout(doc, _) => log::error!("{doc}"),
                    ParseFailure::Completion(_) => log::error!("Not supported on these platforms"),
                }
            } else {
                error.print_message(80);
            }

            return if error.exit_code() == 0 {
                ArgumentParsingResult::Exit
            } else {
                ArgumentParsingResult::ErrorParsing
            };
        },
    };

    // If this is the content process, we'll receive the real options over IPC. So fill in some dummy options for now.
    if let Some(content_process) = cmd_args.content_process {
        return ArgumentParsingResult::ContentProcess(content_process);
    }

    let config_dir = cmd_args
        .config_dir
        .clone()
        .or_else(default_config_dir)
        .inspect(|config_dir| {
            if !config_dir.exists() {