summaryrefslogtreecommitdiff
path: root/src/commands/list.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r--src/commands/list.rs81
1 files changed, 42 insertions, 39 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs
index 8e86973..13176f4 100644
--- a/src/commands/list.rs
+++ b/src/commands/list.rs
@@ -1,4 +1,12 @@
1use 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}; 1use crate::{
2 config::Cfg,
3 db::{
4 config_change_current_list, config_get_current_list, lists_get, lists_insert, lists_remove,
5 lists_version,
6 },
7 error::MLE,
8 update, Modloader,
9};
2 10
3#[derive(Debug, Clone, PartialEq, Eq)] 11#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct List { 12pub struct List {
@@ -8,60 +16,55 @@ pub struct List {
8 pub download_folder: String, 16 pub download_folder: String,
9} 17}
10 18
11pub async fn list(config: Cfg, input: Input) -> MLE<()> {
12
13 match input.clone().list_options.unwrap() {
14 ListOptions::Add => {
15 add(config, input)
16 },
17 ListOptions::Change => {
18 change(config, input)
19 },
20 ListOptions::Remove => {
21 remove(config, input)
22 },
23 ListOptions::Version => {
24 version(config, input).await
25 }
26 }
27}
28
29pub fn get_current_list(config: Cfg) -> MLE<List> { 19pub fn get_current_list(config: Cfg) -> MLE<List> {
30 let id = config_get_current_list(config.clone())?; 20 let id = config_get_current_list(config.clone())?;
31 lists_get(config, id) 21 lists_get(config, id)
32} 22}
33 23
34fn add(config: Cfg, input: Input) -> MLE<()> { 24pub fn list_add(
35 let id = input.list_id.unwrap(); 25 config: Cfg,
36 let mc_version = input.list_mcversion.unwrap(); 26 id: String,
37 let mod_loader = input.modloader.unwrap(); 27 mc_version: String,
38 let download_folder = input.directory.unwrap(); 28 modloader: Modloader,
39 lists_insert(config, id, mc_version, mod_loader, download_folder) 29 directory: String,
30) -> MLE<()> {
31 lists_insert(config, id, mc_version, modloader, directory)
40} 32}
41 33
42fn change(config: Cfg, input: Input) -> MLE<()> { 34pub fn list_change(config: Cfg, id: String) -> MLE<()> {
43 println!("Change default list to: {}", input.clone().list.unwrap().id); 35 //TODO check if list exists
44 config_change_current_list(config, input.list.unwrap().id) 36 println!("Change default list to: {}", id);
37 config_change_current_list(config, id)
45} 38}
46 39
47fn remove(config: Cfg, input: Input) -> MLE<()> { 40pub fn list_remove(config: Cfg, id: String) -> MLE<()> {
48 lists_remove(config, input.list.unwrap().id) 41 lists_remove(config, id)
49} 42}
50 43
51///Changing the current lists version and updating it 44///Changing the current lists version and updating it
52/// 45///
53/// #Arguments 46/// #Arguments
54/// 47///
55/// * `config` - The current config 48/// * `config` - The current config
56/// * `args` - All args, to extract the new version 49/// * `args` - All args, to extract the new version
57async fn version(config: Cfg, input: Input) -> MLE<()> { 50pub async fn list_version(
58 println!("Change version for list {} to minecraft version: {}", input.clone().list.unwrap().id, input.clone().list_mcversion.unwrap()); 51 config: Cfg,
52 id: String,
53 mc_version: String,
54 download: bool,
55 delete: bool,
56) -> MLE<()> {
57 println!(
58 "Change version for list {} to minecraft version: {}",
59 id, mc_version
60 );
59 61
60 lists_version(config.clone(), input.clone().list.ok_or("").unwrap().id, input.clone().list_mcversion.ok_or("").unwrap())?; 62 lists_version(config.clone(), &id, &mc_version)?;
61
62 //Linebreak readability
63 println!("");
64 63
65 println!("Check for updates for new minecraft version in list {}", input.clone().list.unwrap().id); 64 println!(
66 cmd_update(config, vec![input.list.ok_or("").unwrap()], true, input.direct_download, input.delete_old).await 65 "\nCheck for updates for new minecraft version in list {}",
66 id
67 );
68 let list = lists_get(config.clone(), id)?;
69 update(config, vec![list], true, download, delete).await
67} 70}