summaryrefslogtreecommitdiff
path: root/src/commands/list.rs
blob: 13176f459954c2848abe9833c780cda11cc2b183 (plain) (blame)
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
use crate::{
    config::Cfg,
    db::{
        config_change_current_list, config_get_current_list, lists_get, lists_insert, lists_remove,
        lists_version,
    },
    error::MLE,
    update, Modloader,
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct List {
    pub id: String,
    pub mc_version: String,
    pub modloader: Modloader,
    pub download_folder: String,
}

pub fn get_current_list(config: Cfg) -> MLE<List> {
    let id = config_get_current_list(config.clone())?;
    lists_get(config, id)
}

pub fn list_add(
    config: Cfg,
    id: String,
    mc_version: String,
    modloader: Modloader,
    directory: String,
) -> MLE<()> {
    lists_insert(config, id, mc_version, modloader, directory)
}

pub fn list_change(config: Cfg, id: String) -> MLE<()> {
    //TODO check if list exists
    println!("Change default list to: {}", id);
    config_change_current_list(config, id)
}

pub fn list_remove(config: Cfg, id: String) -> MLE<()> {
    lists_remove(config, id)
}

///Changing the current lists version and updating it
///
/// #Arguments
///
/// * `config` - The current config
/// * `args` - All args, to extract the new version
pub async fn list_version(
    config: Cfg,
    id: String,
    mc_version: String,
    download: bool,
    delete: bool,
) -> MLE<()> {
    println!(
        "Change version for list {} to minecraft version: {}",
        id, mc_version
    );

    lists_version(config.clone(), &id, &mc_version)?;

    println!(
        "\nCheck for updates for new minecraft version in list {}",
        id
    );
    let list = lists_get(config.clone(), id)?;
    update(config, vec![list], true, download, delete).await
}