2022-09-25 18:06:34 +00:00
|
|
|
use std::{collections::HashMap, fmt::Display};
|
|
|
|
|
|
|
|
use ansi_term::Color;
|
|
|
|
|
2022-09-25 19:07:46 +00:00
|
|
|
use crate::definition::{Group, Project, TaskDefinition};
|
2022-09-25 18:06:34 +00:00
|
|
|
|
|
|
|
pub fn header<T: Into<String>>(name: T, msg: &str) {
|
|
|
|
let text = format!(" - --=[ {: <20} {: >20} ]=-- -", name.into(), msg);
|
|
|
|
println!("{}", Color::White.bold().paint(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main_error<T: Display>(error: T) {
|
|
|
|
println!("{}\n{}", Color::Red.bold().paint("Error:"), error);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn output<T: Display>(name: T, color: (u8, u8, u8), value: T) {
|
|
|
|
let n = Color::RGB(color.0, color.1, color.2).paint(format!("{}", name));
|
|
|
|
println!("[{}] - {}", n, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn help_text(project: &Project) {
|
|
|
|
println!(
|
|
|
|
"{} {}",
|
|
|
|
Color::White.paint("Conductor"),
|
|
|
|
Color::White.dimmed().paint(env!("CARGO_PKG_VERSION"))
|
|
|
|
);
|
|
|
|
item_list(project);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn item_list(project: &Project) {
|
|
|
|
println!("\n{}", ansi_term::Color::White.bold().paint("GROUPS"));
|
|
|
|
if project.groups.is_empty() {
|
|
|
|
println!("{}", Color::White.dimmed().paint("no groups defined"));
|
|
|
|
} else {
|
|
|
|
for (name, group) in sort_map(&project.groups).iter() {
|
|
|
|
print_group(name, group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("\n{}", ansi_term::Color::White.bold().paint("COMPONENTS"));
|
|
|
|
if project.components.is_empty() {
|
|
|
|
println!("{}", Color::White.dimmed().paint("no components defined"));
|
|
|
|
} else {
|
|
|
|
for (name, _component) in sort_map(&project.components).iter() {
|
|
|
|
println!("{}", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("\n{}", ansi_term::Color::White.bold().paint("TASKS"));
|
|
|
|
if project.tasks.is_empty() && project.components.values().all(|c| c.tasks.is_empty()) {
|
|
|
|
println!("{}", Color::White.dimmed().paint("no tasks defined"));
|
|
|
|
} else {
|
2022-09-25 19:07:46 +00:00
|
|
|
for (name, task) in sort_map(&project.tasks).iter() {
|
|
|
|
print_task(name, task);
|
2022-09-25 18:06:34 +00:00
|
|
|
}
|
2022-09-25 19:07:46 +00:00
|
|
|
|
2022-09-25 18:06:34 +00:00
|
|
|
for (c_name, component) in sort_map(&project.components).iter() {
|
2022-09-25 19:07:46 +00:00
|
|
|
for (t_name, task) in sort_map(&component.tasks).iter() {
|
|
|
|
print_task(&format!("{}:{}", c_name, t_name), task);
|
2022-09-25 18:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn sort_map<V>(map: &HashMap<String, V>) -> Vec<(String, V)>
|
|
|
|
where
|
|
|
|
V: Clone,
|
|
|
|
{
|
|
|
|
let mut items: Vec<(String, V)> = map.iter().map(|v| (v.0.clone(), v.1.clone())).collect();
|
|
|
|
items.sort_by_key(|i| i.0.clone());
|
|
|
|
items
|
|
|
|
}
|
|
|
|
|
2022-09-25 19:07:46 +00:00
|
|
|
fn print_task(name: &str, task: &TaskDefinition) {
|
|
|
|
if let Some(ref desc) = task.description {
|
|
|
|
println!("{: <31}{}", name, desc);
|
|
|
|
} else {
|
|
|
|
println!("{}", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-25 18:06:34 +00:00
|
|
|
fn print_group(name: &str, group: &Group) {
|
|
|
|
if let Some(ref desc) = group.description {
|
|
|
|
println!("{: <31}{}", name, desc);
|
|
|
|
} else {
|
|
|
|
println!(
|
|
|
|
"{: <31}{}: {}",
|
|
|
|
name,
|
|
|
|
Color::White.bold().paint("components"),
|
|
|
|
group.components.join(",")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|