pub mod addignore;
pub mod adopt;
pub mod down;
pub mod fill;
pub mod init;
pub mod list;
pub mod status;
pub mod up;
#[cfg(test)]
mod tests;
use serde::Serialize;
pub fn handler_symbol(handler: &str) -> &'static str {
match handler {
"symlink" => "➞",
"shell" => "⚙",
"path" => "+",
"homebrew" => "⚙",
"install" => "×",
_ => "?",
}
}
pub fn status_label(handler: &str, deployed: bool) -> String {
match (handler, deployed) {
("symlink", true) => "deployed".into(),
("symlink", false) => "pending".into(),
("shell", true) => "sourced".into(),
("shell", false) => "not sourced".into(),
("path", true) => "in PATH".into(),
("path", false) => "not in PATH".into(),
("install", true) => "installed".into(),
("install", false) => "never run".into(),
("homebrew", true) => "installed".into(),
("homebrew", false) => "not installed".into(),
(_, true) => "deployed".into(),
(_, false) => "pending".into(),
}
}
pub fn status_style(deployed: bool) -> &'static str {
if deployed {
"deployed"
} else {
"pending"
}
}
pub fn handler_description(handler: &str, rel_path: &str, user_target: Option<&str>) -> String {
match handler {
"symlink" => {
if let Some(target) = user_target {
target.to_string()
} else {
let display_path = if !rel_path.contains('/') && rel_path.starts_with("dot.") {
format!(".{}", &rel_path[4..])
} else {
format!(".{rel_path}")
};
format!("~/{display_path}")
}
}
"shell" => "shell profile".into(),
"path" => format!("$PATH/{rel_path}"),
"install" => "run script".into(),
"homebrew" => "brew install".into(),
_ => String::new(),
}
}
#[derive(Debug, Clone, Serialize)]
pub struct DisplayFile {
pub name: String,
pub symbol: String,
pub description: String,
pub status: String,
pub status_label: String,
pub handler: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct DisplayPack {
pub name: String,
pub files: Vec<DisplayFile>,
}
#[derive(Debug, Clone, Serialize)]
pub struct PackStatusResult {
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
pub dry_run: bool,
pub packs: Vec<DisplayPack>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub warnings: Vec<String>,
}