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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::lib::{
    config::autoconfig::{get_home_files, get_root_files},
    fsutil::paths::get_root,
    structs::{
        config::KelpDotConfig,
        packages::{PackageInfo, Packages},
    },
};
use anyhow::Context;
use kelpdot_macros::*;
use std::path::Path;
/// Init and autconfig
pub fn init() -> anyhow::Result<()> {
    let root = get_root()?;
    debug_print!("Root: {}", root);
    if Path::new(&format!("{}/kelp.yaml", root)).exists() {
        red_print!("{}/kelp.yaml already exists!", root);
        std::process::exit(1);
    }
    let rootfiles = get_root_files()?;
    let homefiles = get_home_files()?;
    let cfg = KelpDotConfig {
        homefiles: Some(homefiles),
        rootfiles: Some(rootfiles),
        postrun: Some(vec![]),
        prerun: Some(vec![]),
        packages: Some(Packages {
            gentoo: Some(PackageInfo {
                with_file: None,
                packages: Some(vec![]),
            }),
            arch: Some(PackageInfo {
                with_file: None,
                packages: Some(vec![]),
            }),
            debian: Some(PackageInfo {
                with_file: None,
                packages: Some(vec![]),
            }),
            fedora: Some(PackageInfo {
                with_file: None,
                packages: Some(vec![]),
            }),
            gems: Some(PackageInfo {
                with_file: None,
                packages: Some(vec![]),
            }),
            npm: Some(PackageInfo {
                with_file: None,
                packages: Some(vec![]),
            }),
        }),
        postsave: Some(vec![]),
    };
    let conf_path = format!("{}/kelp.yaml", root);
    magenta_print!("[INFO] Config file {} created!", conf_path);
    std::fs::write(conf_path, serde_yaml::to_string(&cfg)?)
        .with_context(|| red!("Unable to write new config file!"))?;
    Ok(())
}