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