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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
pub mod command; 
pub mod errors;
pub mod data;
pub mod extract;

pub mod utils {
    use chiral_common::JobID;

    pub fn ensure_dir() -> std::io::Result<()> {
        let home_dir = chiral_common::fs::default_dir(); 
        if !home_dir.exists() {
            std::fs::create_dir(home_dir)?;
        }

        let reports_dir = get_reports_dir();
        if !reports_dir.exists() {
            std::fs::create_dir(reports_dir)?;
        }

        Ok(())
    }
    pub fn get_filepath(filename: &str) -> std::path::PathBuf {
        chiral_common::fs::default_dir().join(filename)
    }

    pub fn get_history_filepath() -> std::path::PathBuf {
        chiral_common::fs::default_dir().join("history.txt")
    }

    pub fn get_reports_dir() -> std::path::PathBuf {
        chiral_common::fs::default_dir().join("reports")
    }

    pub fn get_report_files() -> std::fs::ReadDir {
        std::fs::read_dir(get_reports_dir()).unwrap()
    }

    pub fn get_report_filepath(job_id: &str) -> std::path::PathBuf {
        let filename = format!("{job_id}.txt");
        get_reports_dir().join(filename)
    }

    pub fn get_report_filepath_with_timestamp(job_id: &str) -> std::path::PathBuf {
        let time_str = chrono::Utc::now().to_string();
        let filename = format!("{job_id} {time_str}.txt");
        get_reports_dir().join(filename)
    }
    
    pub fn get_jobs_filepath() -> std::path::PathBuf {
        chiral_common::fs::default_dir().join("jobs.txt")
    }

    pub fn generate_job_id(op_str: &str) -> JobID {
        op_str.to_string() + "_" + chiral_common::utils::generate_id().as_str() 
    }
}

// font from https://patorjk.com/software/taag/#p=display&f=Bulbhead&t=Chiral
pub const WELCOME_MESSAGE: &str = "\
=========================================================================
=   ______    __      _                     __
=   / ____/   / /_    (_)   _____  ____ _   / /
=   / /       / __ \\  / /   / ___/ / __ `/  / / 
=   / /___    / / / / / /   / /    / /_/ /  / /  
=   \\____/   /_/ /_/ /_/   /_/     \\__,_/  /_/   
=                                              
=   Chiral: a data processing tool for life science written in Rust
=   https://www.chiral.one
=   
=   Chiral command-line-interface provides 3 categories of commands
=       - 'ds' for dataset
=       - 'cu' for computing units
=       - 'job' for computing jobs
=  
=   Entre 'cu example' for quickstart
=   Entre 'ds help' or 'cu help' or 'job help' for command details 
=========================================================================
";