Repository: starship/starship
File: src/configure.rs (Rust)

Code before:
    *new_value.as_value_mut().unwrap().decor_mut() = old_value.as_value().unwrap().decor().clone();

    values.insert(key, new_value);
    Ok(())
}

pub fn get_configuration(context: &Context) -> toml::Table {
    let starship_config = StarshipConfig::initialize(&context.get_config_path_os());

    starship_config.config.unwrap_or(toml::Table::new())
}

pub fn get_configuration_edit(context: &Context) -> Document {
    let config_file_path = context.get_config_path_os();
    let toml_content = StarshipConfig::read_config_content_as_str(&config_file_path);

    toml_content
        .unwrap_or_default()
        .parse::<Document>()
        .expect("Failed to load starship config")
}

pub fn write_configuration(context: &Context, doc: &Document) {
    let config_path = context
        .get_config_path_os()
        .expect("able to get config path");

    let config_str = doc.to_string();

    File::create(config_path)
        .and_then(|mut file| file.write_all(config_str.as_ref()))
        .expect("Error writing starship config");
}

pub fn edit_configuration(
    context: &Context,
    editor_override: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
    // Argument currently only used for testing, but could be used to specify
    // an editor override on the command line.
    let config_path = context
        .get_config_path_os()
        .expect("config path required to edit the config");

    let editor_cmd = shell_words::split(&get_editor(editor_override))?;
    let mut command = match utils::create_command(&editor_cmd[0]) {
        Ok(cmd) => cmd,
        Err(e) => {
            eprintln!(
                "Unable to find editor {:?}. Are $VISUAL and $EDITOR set correctly?",
                editor_cmd[0]

Review comment (suggestion):
This isn't really worse than what we had, but for user-facing errors like this, please prefer using `eprintln!` and `exit`, the output of `expect` can be hard to parse.

Code after:
    *new_value.as_value_mut().unwrap().decor_mut() = old_value.as_value().unwrap().decor().clone();

    values.insert(key, new_value);
    Ok(())
}

pub fn get_configuration(context: &Context) -> toml::Table {
    let starship_config = StarshipConfig::initialize(&context.get_config_path_os());

    starship_config.config.unwrap_or(toml::Table::new())
}

pub fn get_configuration_edit(context: &Context) -> Document {
    let config_file_path = context.get_config_path_os();
    let toml_content = StarshipConfig::read_config_content_as_str(&config_file_path);

    toml_content
        .unwrap_or_default()
        .parse::<Document>()
        .expect("Failed to load starship config")
}

pub fn write_configuration(context: &Context, doc: &Document) {
    let config_path = context.get_config_path_os().unwrap_or_else(|| {
        eprintln!("config path required to write configuration");
        process::exit(1);
    });

    let config_str = doc.to_string();

    File::create(config_path)
        .and_then(|mut file| file.write_all(config_str.as_ref()))
        .expect("Error writing starship config");
}

pub fn edit_configuration(
    context: &Context,
    editor_override: Option<&str>,
) -> Result<(), Box<dyn std::error::Error>> {
    // Argument currently only used for testing, but could be used to specify
    // an editor override on the command line.
    let config_path = context.get_config_path_os().unwrap_or_else(|| {
        eprintln!("config path required to edit configuration");
        process::exit(1);
    });

    let editor_cmd = shell_words::split(&get_editor(editor_override))?;
    let mut command = match utils::create_command(&editor_cmd[0]) {
        Ok(cmd) => cmd,
        Err(e) => {
            eprintln!(