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

Code before:
                _ => Err(StringFormatterError::Custom("Invalid Profile".to_string())),
            },
            Some(name),
        ),
        _ => (StringFormatter::new(""), None),
    };
    if lformatter.is_err() {
        log::error!("Error parsing `format`")
    }
    if rformatter.is_err() {
        log::error!("Error parsing `right_format`")
    }
    if cformatter.is_err() {
        log::error!("Error parsing `continuation_prompt`")
    }
    if pformatter.is_err() {
        if let Some(profile) = profile_name {
            log::error!("Error parsing profile `{}`", profile)
        }
    }
    match (lformatter, rformatter, cformatter, pformatter) {
        (Ok(lf), Ok(rf), Ok(cf), Ok(pf)) => {
            let mut modules: BTreeSet<String> = BTreeSet::new();
            if context.target != Target::Continuation {
                modules.extend(lf.get_variables());
                modules.extend(rf.get_variables());
            }
            match context.target {
                Target::Main => (lf, modules),
                Target::Right => (rf, modules),
                Target::Continuation => (cf, modules),
                Target::Profile(_) => (pf, modules),
            }
        }
        _ => (StringFormatter::raw(">"), BTreeSet::new()),
    }
}

#[cfg(test)]
mod test {
    use super::*;
    use crate::config::StarshipConfig;
    use crate::test::default_context;

    #[test]
    fn main_prompt() {
        let mut context = default_context();
        context.config = StarshipConfig {
            config: Some(toml::toml! {
                add_newline=false
                format="$character"

Review comment (suggestion):
This should either be limited to `matches!(context.target, Target::Main | Target::Right)` instead. Alternatively, this should maybe also handle `Profile(_)` and add either `lf` or `pf` depending on which is active to `modules` allow both to ignore `rf` modules from `$all`.

Code after:
    };

    let rformatter = StringFormatter::new(&config.right_format);

    if formatter.is_err() {
        log::error!("Error parsing `{}`", config_param);
    }
    if rformatter.is_err() {
        log::error!("Error parsing `right_format`")
    }

    match (formatter, rformatter) {
        (Ok(lf), Ok(rf)) => {
            let mut modules: BTreeSet<String> = BTreeSet::new();
            if context.target != Target::Continuation {
                modules.extend(lf.get_variables());
                modules.extend(rf.get_variables());
            }
            (lf, modules)
        }
        _ => (StringFormatter::raw(">"), BTreeSet::new()),
    }
}

#[cfg(feature = "config-schema")]
pub fn print_schema() {
    let schema = schemars::schema_for!(crate::configs::FullConfig);
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

#[derive(Clone, Debug)]
pub struct Preset(pub &'static str);

impl ValueEnum for Preset {
    fn value_variants<'a>() -> &'a [Self] {
        shadow::get_preset_list()
    }

    fn to_possible_value(&self) -> Option<PossibleValue> {
        Some(PossibleValue::new(self.0))
    }
}

pub fn preset_command(name: Option<Preset>, list: bool) {
    if list {
        println!("{}", preset_list());
        return;
    }
    let variant = name.expect("name argument must be specified");
    shadow::print_preset_content(variant.0);
}