aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.rs
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-07-20 22:04:45 +0100
committerLeonardo Bishop <me@leonardobishop.com>2023-07-20 22:15:25 +0100
commitc3a55debe9e4194f83164d412293f27b797627af (patch)
tree027ca943a051bf51c809eec0f590d598df2db9a3 /src/util.rs
Initial commit
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs
new file mode 100644
index 0000000..9c0ed1c
--- /dev/null
+++ b/src/util.rs
@@ -0,0 +1,34 @@
+use crate::config::Step;
+use colored::*;
+
+pub const EXIT_IO_ERROR: i32 = 1;
+pub const EXIT_INSTALL_FAILED: i32 = 2;
+
+// todo: figure out a better way of doing this
+pub fn str_step(step: &Step) -> String {
+ match step {
+ Step::Link(path) => format!("Link {} to {}", &path.from, &path.to),
+ Step::Copy(path) => format!("Copy {} to {}", &path.from, &path.to),
+ Step::Shell(command) => format!("Run {}", command),
+ }
+}
+
+pub fn fmt_step(step: &Step, result: &Result<bool, Box<dyn std::error::Error>>) -> String {
+ let action = str_step(step);
+
+ match result {
+ Ok(true) => { format!("{}{} {} {}", "[".bright_black(), "✔".green(), "]".bright_black(), action) }
+ Ok(false) => { format!("{}{} {} {}", "[".bright_black(), "▼".bright_black(), "]".bright_black(), action) }
+ Err(_) => { format!("{}{} {} {}", "[".bright_black(), "✘".red(), "]".bright_black(), action) }
+ }
+}
+
+pub fn expand_home(path: &str) -> String {
+ let home = std::env::var("HOME").expect("no $HOME");
+ if path.starts_with("~") {
+ let rest_of_path = &path[1..];
+ format!("{}{}", home, rest_of_path)
+ } else {
+ path.to_owned()
+ }
+} \ No newline at end of file