1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::lib::{
config::migration::migrate_configs,
fsutil::paths::get_root,
structs::{config::KelpDotConfig, legacy::LegacyKelpConfig},
};
use kelpdot_macros::*;
use std::path::Path;
pub fn migrate() -> anyhow::Result<()> {
let root = get_root()?;
cyan_print!("[INFO] Migrating dotfiles {}", root);
if !Path::new(&format!("{}/kelp.yaml", root)).exists() {
red_print!("[ERROR] {}/kelp.yaml doesn't exist!", root);
std::process::exit(1);
}
let contents = std::fs::read_to_string(format!("{}/kelp.yaml", root))?;
if serde_yaml::from_str::<KelpDotConfig>(&contents).is_ok() {
green_print!("[MIGRATION] Config is already up-to-date");
std::process::exit(0);
}
let config: LegacyKelpConfig = serde_yaml::from_str(&contents)?;
let new = migrate_configs(config)?;
std::fs::write(format!("{}/kelp.yaml", root), serde_yaml::to_string(&new)?)?;
Ok(())
}