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
|
use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, ListOptions}, cmd_update, error::MLE};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct List {
pub id: String,
pub mc_version: String,
pub modloader: Modloader,
pub download_folder: String,
}
pub async fn list(config: Cfg, input: Input) -> MLE<()> {
match input.clone().list_options.unwrap() {
ListOptions::Add => {
add(config, input)
},
ListOptions::Change => {
change(config, input)
},
ListOptions::Remove => {
remove(config, input)
},
ListOptions::Version => {
version(config, input).await
}
}
}
pub fn get_current_list(config: Cfg) -> MLE<List> {
let id = config_get_current_list(config.clone())?;
lists_get(config, id)
}
fn add(config: Cfg, input: Input) -> MLE<()> {
let id = input.list_id.unwrap();
let mc_version = input.list_mcversion.unwrap();
let mod_loader = input.modloader.unwrap();
let download_folder = input.directory.unwrap();
lists_insert(config, id, mc_version, mod_loader, download_folder)
}
fn change(config: Cfg, input: Input) -> MLE<()> {
println!("Change default list to: {}", input.clone().list.unwrap().id);
config_change_current_list(config, input.list.unwrap().id)
}
fn remove(config: Cfg, input: Input) -> MLE<()> {
lists_remove(config, input.list.unwrap().id)
}
///Changing the current lists version and updating it
///
/// #Arguments
///
/// * `config` - The current config
/// * `args` - All args, to extract the new version
async fn version(config: Cfg, input: Input) -> MLE<()> {
println!("Change version for list {} to minecraft version: {}", input.clone().list.unwrap().id, input.clone().list_mcversion.unwrap());
lists_version(config.clone(), input.clone().list.ok_or("").unwrap().id, input.clone().list_mcversion.ok_or("").unwrap())?;
//Linebreak readability
println!("");
println!("Check for updates for new minecraft version in list {}", input.clone().list.unwrap().id);
cmd_update(config, vec![input.list.ok_or("").unwrap()], true, input.direct_download, input.delete_old).await
}
|