use colored::Colorize;
use crate::{config::Config, state::LocalState};
pub fn list(config: &Config, state: &LocalState) -> anyhow::Result<()> {
let upstream_channels = config.upstream_manifest()?.get_channels();
crate::report::prepare_stdout_color();
let toolchains_display: Vec<String> = upstream_channels
.map(|channel| {
let channel_name = &channel.name;
let installed_indicator = match state.get(&channel.name) {
Some(installation) if installation.as_channel().is_partially_installed(channel) => {
format!(" {}", "(partially installed)".yellow())
},
Some(_) => format!(" {}", "(installed)".green()),
None => String::new(),
};
format!("{channel_name}{installed_indicator}")
})
.collect();
println!("{}", "Available toolchains upstream:".bold().underline());
for toolchain in toolchains_display {
println!("{toolchain}");
}
Ok(())
}