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
use colored::*;

use crate::modules::commands::init::run_init;
use crate::modules::commands::migrate::run_migrate;
use crate::modules::commands::replicate::run_replicate;
use crate::modules::commands::tables::run_tables;
use crate::modules::services::utils::init_check;
use crate::modules::types::cli::Cli;

pub mod init;
pub mod migrate;
pub mod replicate;
pub mod tables;

/// Init new replicator
pub fn init(args: Cli) -> () {
    if args.overwrite {
        run_init(args);
    } else {
        let init_state: bool = init_check(false);

        // Check if project already exists
        if !init_state {
            run_init(args);
        } else {
            println!("{}", "Replicator config already exists!".red());
        }
    }
}

/// Replicate persistent data
pub fn replicate(args: Cli) -> () {
    let init_state: bool = init_check(false);

    if init_state {
        run_replicate(args);
    } else {
        println!("{}", "Replicator config does not exist. Init first!".red());
    }
}

/// Migrate persistent data to database
pub fn migrate(args: Cli) -> () {
    let init_state: bool = init_check(false);

    if init_state {
        run_migrate(args);
    } else {
        println!("{}", "Replicator config does not exist. Init first!".red());
    }
}

/// List all tables or collections
pub fn tables(args: Cli) -> () {
    let init_state: bool = init_check(false);

    if init_state {
        run_tables(args);
    } else {
        println!("{}", "Replicator config does not exist. Init first!".red());
    }
}

// TODO: Add delete command for deleting replicated data