diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/apis/modrinth.rs | 6 | ||||
-rw-r--r-- | src/commands/download.rs | 11 | ||||
-rw-r--r-- | src/commands/io.rs | 30 | ||||
-rw-r--r-- | src/commands/list.rs | 73 | ||||
-rw-r--r-- | src/commands/mod.rs | 12 | ||||
-rw-r--r-- | src/commands/update.rs | 18 | ||||
-rw-r--r-- | src/db.rs | 13 | ||||
-rw-r--r-- | src/error.rs | 12 | ||||
-rw-r--r-- | src/files.rs | 6 | ||||
-rw-r--r-- | src/input.rs | 115 | ||||
-rw-r--r-- | src/lib.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 47 |
12 files changed, 194 insertions, 155 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 78073e6..9890cf2 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -3,7 +3,7 @@ use chrono::{DateTime, FixedOffset}; | |||
3 | use reqwest::Client; | 3 | use reqwest::Client; |
4 | use serde::Deserialize; | 4 | use serde::Deserialize; |
5 | 5 | ||
6 | use crate::{Modloader, List}; | 6 | use crate::{Modloader, List, error::{MLE, MLError, ErrorType}}; |
7 | 7 | ||
8 | #[derive(Debug, Deserialize, Clone)] | 8 | #[derive(Debug, Deserialize, Clone)] |
9 | pub struct Project { | 9 | pub struct Project { |
@@ -177,9 +177,9 @@ pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version | |||
177 | serde_json::from_slice(&data).unwrap() | 177 | serde_json::from_slice(&data).unwrap() |
178 | } | 178 | } |
179 | 179 | ||
180 | pub fn extract_current_version(versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> { | 180 | pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> { |
181 | match versions.len() { | 181 | match versions.len() { |
182 | 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))), | 182 | 0 => Err(MLError::new(ErrorType::ModError, "NO_VERSIONS_AVAILABLE")), |
183 | 1.. => { | 183 | 1.. => { |
184 | let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; | 184 | let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; |
185 | for ver in versions { | 185 | for ver in versions { |
diff --git a/src/commands/download.rs b/src/commands/download.rs index b958bf3..0f63876 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions}; | 1 | use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions, error::{MLE, ErrorType, MLError}}; |
2 | use crate::{List, get_current_list, config::Cfg, input::Input}; | 2 | use crate::{List, get_current_list, config::Cfg, input::Input}; |
3 | 3 | ||
4 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 4 | pub async fn download(config: Cfg, input: Input) -> MLE<()> { |
5 | 5 | ||
6 | let mut liststack: Vec<List> = vec![]; | 6 | let mut liststack: Vec<List> = vec![]; |
7 | if input.all_lists { | 7 | if input.all_lists { |
@@ -18,7 +18,10 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::erro | |||
18 | for current_list in liststack { | 18 | for current_list in liststack { |
19 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; | 19 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; |
20 | println!("To download: {:#?}", downloaded_versions); | 20 | println!("To download: {:#?}", downloaded_versions); |
21 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; | 21 | let current_version_ids = match userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id)) { |
22 | Ok(i) => Ok(i), | ||
23 | Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), | ||
24 | }?; | ||
22 | 25 | ||
23 | let mut to_download: Vec<String> = vec![]; | 26 | let mut to_download: Vec<String> = vec![]; |
24 | //(mod_id, version_id) | 27 | //(mod_id, version_id) |
@@ -33,7 +36,7 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::erro | |||
33 | if current_download.is_none() || input.clean { | 36 | if current_download.is_none() || input.clean { |
34 | to_download.push(current_version); | 37 | to_download.push(current_version); |
35 | } else { | 38 | } else { |
36 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?; | 39 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG").unwrap(); |
37 | if ¤t_version != downloaded_version { | 40 | if ¤t_version != downloaded_version { |
38 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); | 41 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); |
39 | to_download.push(current_version); | 42 | to_download.push(current_version); |
diff --git a/src/commands/io.rs b/src/commands/io.rs index 6c4a4d3..4835e3d 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -2,7 +2,7 @@ use std::fs::File; | |||
2 | use std::io::prelude::*; | 2 | use std::io::prelude::*; |
3 | use serde::{Serialize, Deserialize}; | 3 | use serde::{Serialize, Deserialize}; |
4 | 4 | ||
5 | use crate::{input::{Input, Subcmd}, db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, mod_add, List, devdir}; | 5 | use crate::{input::{Input, IoOptions}, db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, /*mod_add,*/ List, devdir, error::MLE}; |
6 | 6 | ||
7 | #[derive(Debug, Serialize, Deserialize)] | 7 | #[derive(Debug, Serialize, Deserialize)] |
8 | struct Export { | 8 | struct Export { |
@@ -19,7 +19,7 @@ struct ExportList { | |||
19 | } | 19 | } |
20 | 20 | ||
21 | impl ExportList { | 21 | impl ExportList { |
22 | pub fn from(config: Cfg, list_id: String, download: bool) -> Result<Self, Box<dyn std::error::Error>> { | 22 | pub fn from(config: Cfg, list_id: String, download: bool) -> MLE<Self> { |
23 | 23 | ||
24 | let list = lists_get(config.clone(), String::from(&list_id))?; | 24 | let list = lists_get(config.clone(), String::from(&list_id))?; |
25 | 25 | ||
@@ -32,26 +32,22 @@ impl ExportList { | |||
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | pub async fn io(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 35 | pub async fn io(config: Cfg, input: Input) -> MLE<()> { |
36 | 36 | ||
37 | match input.subcommand.clone().ok_or("INVALID_INPUT")? { | 37 | match input.clone().io_options.unwrap() { |
38 | Subcmd::Export => { export(config, input)? }, | 38 | IoOptions::Export => { export(config, input)? }, |
39 | Subcmd::Import => { import(config, input.args).await? }, | 39 | IoOptions::Import => { import(config, input).await? }, |
40 | _ => { }, | ||
41 | } | 40 | } |
42 | 41 | ||
43 | Ok(()) | 42 | Ok(()) |
44 | } | 43 | } |
45 | 44 | ||
46 | fn export(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 45 | fn export(config: Cfg, input: Input) -> MLE<()> { |
47 | let mut list_ids: Vec<String> = vec![]; | 46 | let mut list_ids: Vec<String> = vec![]; |
48 | if input.all_lists { | 47 | if input.all_lists { |
49 | list_ids = lists_get_all_ids(config.clone())?; | 48 | list_ids = lists_get_all_ids(config.clone())?; |
50 | } else { | 49 | } else { |
51 | let args = input.args.ok_or("NO_ARGS")?; | 50 | list_ids.push(lists_get(config.clone(), input.list.unwrap().id)?.id); |
52 | for arg in args { | ||
53 | list_ids.push(lists_get(config.clone(), arg)?.id); | ||
54 | } | ||
55 | } | 51 | } |
56 | let mut lists: Vec<ExportList> = vec![]; | 52 | let mut lists: Vec<ExportList> = vec![]; |
57 | for list_id in list_ids { | 53 | for list_id in list_ids { |
@@ -68,10 +64,10 @@ fn export(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | |||
68 | Ok(()) | 64 | Ok(()) |
69 | } | 65 | } |
70 | 66 | ||
71 | async fn import(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { | 67 | async fn import(config: Cfg, input: Input) -> MLE<()> { |
72 | 68 | ||
73 | let filestr: String = match args { | 69 | let filestr: String = match input.file { |
74 | Some(args) => String::from(&args[0]), | 70 | Some(args) => String::from(args), |
75 | None => String::from(devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str())), | 71 | None => String::from(devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str())), |
76 | }; | 72 | }; |
77 | 73 | ||
@@ -83,14 +79,14 @@ async fn import(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn st | |||
83 | println!("{:#?}", export); | 79 | println!("{:#?}", export); |
84 | 80 | ||
85 | for exportlist in export.lists { | 81 | for exportlist in export.lists { |
86 | let list = List { id: exportlist.id, mc_version: exportlist.mc_version, modloader: Modloader::from(&exportlist.launcher)?, download_folder: exportlist.download_folder.ok_or("NO_DL")? }; | 82 | let list = List { id: exportlist.id, mc_version: exportlist.mc_version, modloader: Modloader::from(&exportlist.launcher)?, download_folder: exportlist.download_folder.ok_or("NO_DL").unwrap() }; |
87 | lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?; | 83 | lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?; |
88 | let mods: Vec<&str> = exportlist.mods.split("|").collect(); | 84 | let mods: Vec<&str> = exportlist.mods.split("|").collect(); |
89 | let mut mod_ids = vec![]; | 85 | let mut mod_ids = vec![]; |
90 | for mod_id in mods { | 86 | for mod_id in mods { |
91 | mod_ids.push(String::from(mod_id)); | 87 | mod_ids.push(String::from(mod_id)); |
92 | }; | 88 | }; |
93 | mod_add(config.clone(), mod_ids, list.clone(), false).await?; | 89 | //mod_add(config.clone(), mod_ids, list.clone(), false).await?; |
94 | } | 90 | } |
95 | Ok(()) | 91 | Ok(()) |
96 | } | 92 | } |
diff --git a/src/commands/list.rs b/src/commands/list.rs index 2fec1c7..bc58787 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -1,6 +1,4 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get}, Modloader, config::Cfg, input::{Input, ListOptions}, /*cmd_update,*/ error::MLE, /*modrinth::MCVersionType*/}; |
2 | |||
3 | use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, ListOptions}, /*cmd_update,*/ error::{MLE, ErrorType, MLError}, /*modrinth::MCVersionType*/}; | ||
4 | 2 | ||
5 | #[derive(Debug, Clone, PartialEq, Eq)] | 3 | #[derive(Debug, Clone, PartialEq, Eq)] |
6 | pub struct List { | 4 | pub struct List { |
@@ -9,78 +7,49 @@ pub struct List { | |||
9 | pub modloader: Modloader, | 7 | pub modloader: Modloader, |
10 | pub download_folder: String, | 8 | pub download_folder: String, |
11 | } | 9 | } |
12 | /* | ||
13 | pub async fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | ||
14 | 10 | ||
15 | match input.list_options.ok_or("")? { | 11 | pub async fn list(config: Cfg, input: Input) -> MLE<()> { |
12 | |||
13 | match input.clone().list_options.unwrap() { | ||
16 | ListOptions::Add => { | 14 | ListOptions::Add => { |
17 | match add(config, input.args.ok_or("")?) { | 15 | add(config, input) |
18 | Ok(..) => Ok(()), | ||
19 | Err(e) => Err(Box::new(e)) | ||
20 | } | ||
21 | }, | 16 | }, |
22 | ListOptions::Change => { | 17 | ListOptions::Change => { |
23 | change(config, input.args) | 18 | change(config, input) |
24 | }, | 19 | }, |
25 | ListOptions::Remove => { | 20 | ListOptions::Remove => { |
26 | match remove(config, input.args.ok_or("")?) { | 21 | remove(config, input) |
27 | Ok(..) => Ok(()), | ||
28 | Err(e) => Err(Box::new(e)) | ||
29 | } | ||
30 | }, | 22 | }, |
23 | /* | ||
31 | Subcmd::Version => { | 24 | Subcmd::Version => { |
32 | match version(config, Some(input.args.ok_or("NO_VERSION")?), Some(MCVersionType::Release)).await { | 25 | match version(config, Some(input.args.ok_or("NO_VERSION")?), Some(MCVersionType::Release)).await { |
33 | Ok(..) => Ok(()), | 26 | Ok(..) => Ok(()), |
34 | Err(e) => Err(Box::new(e)) | 27 | Err(e) => Err(Box::new(e)) |
35 | } | 28 | } |
36 | } | 29 | }*/ |
37 | _ => { | ||
38 | Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) | ||
39 | } | ||
40 | } | 30 | } |
41 | } | 31 | } |
42 | */ | 32 | |
43 | pub fn get_current_list(config: Cfg) -> MLE<List> { | 33 | pub fn get_current_list(config: Cfg) -> MLE<List> { |
44 | let id = config_get_current_list(config.clone())?; | 34 | let id = config_get_current_list(config.clone())?; |
45 | lists_get(config, id) | 35 | lists_get(config, id) |
46 | } | 36 | } |
47 | 37 | ||
48 | fn add(config: Cfg, args: Vec<String>) -> MLE<()> { | 38 | fn add(config: Cfg, input: Input) -> MLE<()> { |
49 | match args.len() { | 39 | let id = input.list_id.unwrap(); |
50 | 1 | 2 | 3 => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_FEW_ARGUMENTS")), | 40 | let mc_version = input.list_mcversion.unwrap(); |
51 | 4 => { | 41 | let mod_loader = input.modloader.unwrap(); |
52 | let id = String::from(&args[0]); | 42 | let download_folder = input.directory.unwrap(); |
53 | let mc_version = String::from(&args[1]); | 43 | lists_insert(config, id, mc_version, mod_loader, download_folder) |
54 | let mod_loader = Modloader::from(&args[2])?; | ||
55 | let download_folder = String::from(&args[3]); | ||
56 | lists_insert(config, id, mc_version, mod_loader, download_folder) | ||
57 | }, | ||
58 | 5.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")), | ||
59 | _ => panic!("list arguments should never be zero or lower"), | ||
60 | } | ||
61 | } | 44 | } |
62 | 45 | ||
63 | fn change(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { | 46 | fn change(config: Cfg, input: Input) -> MLE<()> { |
64 | let lists = lists_get_all_ids(config.clone())?; | 47 | //TODO reimplement current list |
65 | if args.is_none() { println!("Currently selected list: {}", get_current_list(config)?.id); return Ok(()) }; | 48 | config_change_current_list(config, input.list.unwrap().id) |
66 | let argsvec = args.ok_or("BAH")?; | ||
67 | match argsvec.len() { | ||
68 | 1 => { | ||
69 | let list = String::from(&argsvec[0]); | ||
70 | if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; | ||
71 | config_change_current_list(config, list) | ||
72 | }, | ||
73 | 2.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), | ||
74 | _ => panic!("list arguments should never lower than zero"), | ||
75 | } | ||
76 | } | 49 | } |
77 | 50 | ||
78 | fn remove(config: Cfg, args: Vec<String>) -> MLE<()> { | 51 | fn remove(config: Cfg, input: Input) -> MLE<()> { |
79 | match args.len() { | 52 | lists_remove(config, input.list.unwrap().id) |
80 | 1 => lists_remove(config, String::from(&args[0])), | ||
81 | 2.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")), | ||
82 | _ => panic!("list arguments should never be zero or lower"), | ||
83 | } | ||
84 | } | 53 | } |
85 | 54 | ||
86 | /* | 55 | /* |
diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 29fc600..527afc7 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs | |||
@@ -1,13 +1,13 @@ | |||
1 | //pub mod modification; | 1 | //pub mod modification; |
2 | pub mod list; | 2 | pub mod list; |
3 | //pub mod update; | 3 | pub mod update; |
4 | //pub mod setup; | 4 | //pub mod setup; |
5 | //pub mod download; | 5 | pub mod download; |
6 | //pub mod io; | 6 | pub mod io; |
7 | 7 | ||
8 | //pub use modification::*; | 8 | //pub use modification::*; |
9 | pub use list::*; | 9 | pub use list::*; |
10 | //pub use update::*; | 10 | pub use update::*; |
11 | //pub use setup::*; | 11 | //pub use setup::*; |
12 | //pub use download::*; | 12 | pub use download::*; |
13 | //pub use io::*; | 13 | pub use io::*; |
diff --git a/src/commands/update.rs b/src/commands/update.rs index ca28130..068c3f3 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | use std::io::{Error, ErrorKind}; | ||
2 | |||
3 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}, error::{MLE, MLError, ErrorType}}; | 1 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}, error::{MLE, MLError, ErrorType}}; |
4 | 2 | ||
5 | pub async fn update(config: Cfg, input: Input) -> MLE<()> { | 3 | pub async fn update(config: Cfg, input: Input) -> MLE<()> { |
@@ -93,7 +91,7 @@ pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_d | |||
93 | Ok(()) | 91 | Ok(()) |
94 | } | 92 | } |
95 | 93 | ||
96 | async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> Result<Version, Box<dyn std::error::Error>> { | 94 | async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> MLE<Version> { |
97 | println!("Checking update for '{}' in {}", project.title, list.id); | 95 | println!("Checking update for '{}' in {}", project.title, list.id); |
98 | 96 | ||
99 | let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; | 97 | let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; |
@@ -114,14 +112,20 @@ async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) | |||
114 | //get new versions | 112 | //get new versions |
115 | print!(" | getting new version"); | 113 | print!(" | getting new version"); |
116 | let current_str = extract_current_version(applicable_versions.clone())?; | 114 | let current_str = extract_current_version(applicable_versions.clone())?; |
117 | let current_ver = applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("")?; | 115 | let current_ver = match applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("!no current version in applicable_versions") { |
116 | Ok(v) => Ok(v), | ||
117 | Err(e) => Err(MLError::new(ErrorType::Other, e)), | ||
118 | }?; | ||
118 | current.push(current_ver.clone()); | 119 | current.push(current_ver.clone()); |
119 | 120 | ||
120 | let link = current_ver.files.into_iter().find(|f| f.primary).ok_or("")?.url; | 121 | let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") { |
121 | userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id)?; | 122 | Ok(p) => Ok(p), |
123 | Err(e) => Err(MLError::new(ErrorType::Other, e)), | ||
124 | }?.url; | ||
125 | userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id); | ||
122 | } | 126 | } |
123 | 127 | ||
124 | if current.is_empty() { return Err(Box::new(Error::new(ErrorKind::NotFound, "NO_UPDATE_AVAILABLE"))) }; | 128 | if current.is_empty() { return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")) }; |
125 | 129 | ||
126 | println!(" | ✔️"); | 130 | println!(" | ✔️"); |
127 | Ok(current[0].clone()) | 131 | Ok(current[0].clone()) |
@@ -177,7 +177,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE<Vec<String>> { | |||
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { | 180 | pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> MLE<()> { |
181 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 181 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
182 | let connection = Connection::open(data)?; | 182 | let connection = Connection::open(data)?; |
183 | 183 | ||
@@ -186,7 +186,7 @@ pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<( | |||
186 | } | 186 | } |
187 | 187 | ||
188 | 188 | ||
189 | pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { | 189 | pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> MLE<String> { |
190 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 190 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
191 | let connection = Connection::open(data).unwrap(); | 191 | let connection = Connection::open(data).unwrap(); |
192 | 192 | ||
@@ -201,12 +201,12 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St | |||
201 | }; | 201 | }; |
202 | 202 | ||
203 | match version.is_empty() { | 203 | match version.is_empty() { |
204 | true => Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), | 204 | true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), |
205 | false => Ok(version), | 205 | false => Ok(version), |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { | 209 | pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> MLE<Vec<(String, String)>> { |
210 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 210 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
211 | let connection = Connection::open(data)?; | 211 | let connection = Connection::open(data)?; |
212 | 212 | ||
@@ -221,7 +221,7 @@ pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: Stri | |||
221 | versions.push((out[0].to_owned(), out[1].to_owned())); | 221 | versions.push((out[0].to_owned(), out[1].to_owned())); |
222 | }; | 222 | }; |
223 | 223 | ||
224 | if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; | 224 | if versions.is_empty() { return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); }; |
225 | 225 | ||
226 | Ok(versions) | 226 | Ok(versions) |
227 | } | 227 | } |
@@ -349,6 +349,7 @@ pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result<Vec<St | |||
349 | } | 349 | } |
350 | 350 | ||
351 | //lists | 351 | //lists |
352 | ///Inserts into lists table and creates new table | ||
352 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> MLE<()> { | 353 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> MLE<()> { |
353 | println!("Creating list {}", id); | 354 | println!("Creating list {}", id); |
354 | 355 | ||
@@ -420,7 +421,7 @@ pub fn lists_get_all_ids(config: Cfg) -> MLE<Vec<String>> { | |||
420 | } | 421 | } |
421 | 422 | ||
422 | //config | 423 | //config |
423 | pub fn config_change_current_list(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { | 424 | pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { |
424 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 425 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
425 | let connection = Connection::open(data)?; | 426 | let connection = Connection::open(data)?; |
426 | 427 | ||
diff --git a/src/error.rs b/src/error.rs index dbe7224..a1f5f2e 100644 --- a/src/error.rs +++ b/src/error.rs | |||
@@ -15,9 +15,11 @@ pub enum ErrorType { | |||
15 | ArgumentCountError, | 15 | ArgumentCountError, |
16 | ConfigError, | 16 | ConfigError, |
17 | DBError, | 17 | DBError, |
18 | ModError, | ||
18 | LibToml, | 19 | LibToml, |
19 | LibSql, | 20 | LibSql, |
20 | LibReq, | 21 | LibReq, |
22 | LibChrono, | ||
21 | IoError, | 23 | IoError, |
22 | Other, | 24 | Other, |
23 | } | 25 | } |
@@ -31,13 +33,15 @@ impl std::error::Error for MLError { | |||
31 | impl fmt::Display for MLError { | 33 | impl fmt::Display for MLError { |
32 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 34 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
33 | match self.etype { | 35 | match self.etype { |
34 | ErrorType::ArgumentError => write!(f, "Wrong argument"), | 36 | ErrorType::ArgumentError => write!(f, "User input not accepted: {}", self.message), |
35 | ErrorType::ArgumentCountError => write!(f, "Too many/too few arguments"), | 37 | ErrorType::ArgumentCountError => write!(f, "Too many/too few arguments"), |
36 | ErrorType::ConfigError => write!(f, "CONFIG"), | 38 | ErrorType::ConfigError => write!(f, "CONFIG"), |
37 | ErrorType::DBError => write!(f, "DATABASE"), | 39 | ErrorType::DBError => write!(f, "DATABASE"), |
40 | ErrorType::ModError => write!(f, "Mod: {}", self.message), | ||
38 | ErrorType::LibToml => write!(f, "TOML"), | 41 | ErrorType::LibToml => write!(f, "TOML"), |
39 | ErrorType::LibSql => write!(f, "SQL"), | 42 | ErrorType::LibSql => write!(f, "SQL"), |
40 | ErrorType::LibReq => write!(f, "REQWEST"), | 43 | ErrorType::LibReq => write!(f, "REQWEST"), |
44 | ErrorType::LibChrono => write!(f, "Chrono error: {}", self.message), | ||
41 | ErrorType::IoError => write!(f, "IO"), | 45 | ErrorType::IoError => write!(f, "IO"), |
42 | ErrorType::Other => write!(f, "OTHER") | 46 | ErrorType::Other => write!(f, "OTHER") |
43 | } | 47 | } |
@@ -68,6 +72,12 @@ impl From<toml::ser::Error> for MLError { | |||
68 | } | 72 | } |
69 | } | 73 | } |
70 | 74 | ||
75 | impl From<chrono::ParseError> for MLError { | ||
76 | fn from(error: chrono::ParseError) -> Self { | ||
77 | Self { etype: ErrorType::LibChrono, message: error.to_string() } | ||
78 | } | ||
79 | } | ||
80 | |||
71 | impl From<std::io::Error> for MLError { | 81 | impl From<std::io::Error> for MLError { |
72 | fn from(error: std::io::Error) -> Self { | 82 | fn from(error: std::io::Error) -> Self { |
73 | Self { etype: ErrorType::IoError, message: error.to_string() } | 83 | Self { etype: ErrorType::IoError, message: error.to_string() } |
diff --git a/src/files.rs b/src/files.rs index 998ed32..14e5636 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -85,12 +85,12 @@ pub fn get_file_path(list: List, versionid: String) -> MLE<String> { | |||
85 | Ok(filename.to_owned()) | 85 | Ok(filename.to_owned()) |
86 | } | 86 | } |
87 | 87 | ||
88 | pub fn get_downloaded_versions(list: List) -> Result<HashMap<String, String>, Box<dyn std::error::Error>> { | 88 | pub fn get_downloaded_versions(list: List) -> MLE<HashMap<String, String>> { |
89 | let mut versions: HashMap<String, String> = HashMap::new(); | 89 | let mut versions: HashMap<String, String> = HashMap::new(); |
90 | for file in read_dir(&list.download_folder)? { | 90 | for file in read_dir(&list.download_folder)? { |
91 | let path = file?.path(); | 91 | let path = file?.path(); |
92 | if path.is_file() && path.extension().ok_or("BAH")? == "jar" { | 92 | if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { |
93 | let pathstr = path.to_str().ok_or("BAH")?; | 93 | let pathstr = path.to_str().ok_or("BAH").unwrap(); |
94 | let namesplit: Vec<&str> = pathstr.split('.').collect(); | 94 | let namesplit: Vec<&str> = pathstr.split('.').collect(); |
95 | versions.insert(String::from(namesplit[namesplit.len() - 3]), String::from(namesplit[namesplit.len() - 2])); | 95 | versions.insert(String::from(namesplit[namesplit.len() - 3]), String::from(namesplit[namesplit.len() - 2])); |
96 | } | 96 | } |
diff --git a/src/input.rs b/src/input.rs index 4e59c50..be24660 100644 --- a/src/input.rs +++ b/src/input.rs | |||
@@ -7,6 +7,10 @@ pub struct Input { | |||
7 | pub mod_id: Option<String>, | 7 | pub mod_id: Option<String>, |
8 | pub mod_version: Option<String>, | 8 | pub mod_version: Option<String>, |
9 | pub set_version: bool, | 9 | pub set_version: bool, |
10 | pub all_lists: bool, | ||
11 | pub clean: bool, | ||
12 | pub direct_download: bool, | ||
13 | pub delete_old: bool, | ||
10 | pub list: Option<List>, | 14 | pub list: Option<List>, |
11 | pub list_options: Option<ListOptions>, | 15 | pub list_options: Option<ListOptions>, |
12 | pub list_id: Option<String>, | 16 | pub list_id: Option<String>, |
@@ -24,6 +28,7 @@ pub enum Cmd { | |||
24 | Update, | 28 | Update, |
25 | Download, | 29 | Download, |
26 | Io, | 30 | Io, |
31 | Version, | ||
27 | } | 32 | } |
28 | 33 | ||
29 | #[derive(Debug, Clone, PartialEq, Eq)] | 34 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -59,6 +64,10 @@ impl Input { | |||
59 | let mut mod_id: Option<String> = None; | 64 | let mut mod_id: Option<String> = None; |
60 | let mut mod_version: Option<String> = None; | 65 | let mut mod_version: Option<String> = None; |
61 | let mut set_version = false; | 66 | let mut set_version = false; |
67 | let mut all_lists = false; | ||
68 | let mut clean = false; | ||
69 | let mut direct_download = true; | ||
70 | let mut delete_old = false; | ||
62 | let mut list: Option<List> = None; | 71 | let mut list: Option<List> = None; |
63 | let mut list_options: Option<ListOptions> = None; | 72 | let mut list_options: Option<ListOptions> = None; |
64 | let mut list_id: Option<String> = None; | 73 | let mut list_id: Option<String> = None; |
@@ -71,7 +80,9 @@ impl Input { | |||
71 | for arg in args { | 80 | for arg in args { |
72 | let arg_split: Vec<&str> = arg.trim().split(" ").collect(); | 81 | let arg_split: Vec<&str> = arg.trim().split(" ").collect(); |
73 | match arg_split[0] { | 82 | match arg_split[0] { |
74 | "v" | "version" => { show_version(); }, | 83 | "v" | "version" => { |
84 | command = Some(Cmd::Version); | ||
85 | }, | ||
75 | "d" | "download" => { | 86 | "d" | "download" => { |
76 | command = Some(Cmd::Download); | 87 | command = Some(Cmd::Download); |
77 | }, | 88 | }, |
@@ -81,25 +92,39 @@ impl Input { | |||
81 | "ma" => { | 92 | "ma" => { |
82 | command = Some(Cmd::Mod); | 93 | command = Some(Cmd::Mod); |
83 | mod_options = Some(ModOptions::Add); | 94 | mod_options = Some(ModOptions::Add); |
84 | if arg_split.len() != 1 { | 95 | if arg_split.len() == 2 { |
85 | mod_id = Some(String::from(arg_split[1])); | 96 | mod_id = Some(String::from(arg_split[1])); |
86 | } | 97 | } |
87 | }, | 98 | }, |
99 | "mv" => { | ||
100 | command = Some(Cmd::Mod); | ||
101 | mod_options = Some(ModOptions::Add); | ||
102 | if arg_split.len() == 2 { | ||
103 | mod_version = Some(String::from(arg_split[1])); | ||
104 | }; | ||
105 | }, | ||
88 | "mr" => { | 106 | "mr" => { |
89 | command = Some(Cmd::Mod); | 107 | command = Some(Cmd::Mod); |
90 | mod_options = Some(ModOptions::Remove); | 108 | mod_options = Some(ModOptions::Remove); |
91 | if arg_split.len() != 1 { | 109 | if arg_split.len() == 2 { |
92 | mod_id = Some(String::from(arg_split[1])); | 110 | mod_id = Some(String::from(arg_split[1])); |
93 | } | 111 | } |
94 | }, | 112 | }, |
95 | "mv" => { | 113 | "set_version" => { |
96 | if arg_split.len() != 1 { | ||
97 | mod_version = Some(String::from(arg_split[1])); | ||
98 | }; | ||
99 | }, | ||
100 | "set-version" => { | ||
101 | set_version = true; | 114 | set_version = true; |
102 | }, | 115 | }, |
116 | "all_lists" => { | ||
117 | all_lists = true; | ||
118 | }, | ||
119 | "clean" => { | ||
120 | clean = true; | ||
121 | }, | ||
122 | "direct-download" => { | ||
123 | direct_download = true; | ||
124 | }, | ||
125 | "delete_old" => { | ||
126 | delete_old = true; | ||
127 | }, | ||
103 | "l" => { | 128 | "l" => { |
104 | list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); | 129 | list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); |
105 | } | 130 | } |
@@ -111,7 +136,10 @@ impl Input { | |||
111 | "lr" => { | 136 | "lr" => { |
112 | command = Some(Cmd::List); | 137 | command = Some(Cmd::List); |
113 | list_options = Some(ListOptions::Remove); | 138 | list_options = Some(ListOptions::Remove); |
114 | list_id = Some(String::from(arg_split[1])); | 139 | if arg_split.len() == 2 { |
140 | list_id = Some(String::from(arg_split[1])); | ||
141 | list = Some(lists_get(config.clone(), list_id.clone().unwrap())?) | ||
142 | } | ||
115 | }, | 143 | }, |
116 | "lc" => { | 144 | "lc" => { |
117 | command = Some(Cmd::List); | 145 | command = Some(Cmd::List); |
@@ -138,7 +166,7 @@ impl Input { | |||
138 | "f" => { | 166 | "f" => { |
139 | file = Some(String::from(arg_split[1])); | 167 | file = Some(String::from(arg_split[1])); |
140 | }, | 168 | }, |
141 | _ => return Err(MLError::new(ErrorType::ArgumentError, "UnknownArgument")), | 169 | _ => return Err(MLError::new(ErrorType::ArgumentError, format!("Unknown Argument ({})", arg_split[0]).as_str())), |
142 | } | 170 | } |
143 | } | 171 | } |
144 | 172 | ||
@@ -148,6 +176,10 @@ impl Input { | |||
148 | mod_id, | 176 | mod_id, |
149 | mod_version, | 177 | mod_version, |
150 | set_version, | 178 | set_version, |
179 | all_lists, | ||
180 | clean, | ||
181 | direct_download, | ||
182 | delete_old, | ||
151 | list, | 183 | list, |
152 | list_options, | 184 | list_options, |
153 | list_id, | 185 | list_id, |
@@ -160,47 +192,32 @@ impl Input { | |||
160 | } | 192 | } |
161 | } | 193 | } |
162 | 194 | ||
163 | fn show_version() { | ||
164 | match std::env::var("DEV") { | ||
165 | Ok(dev) => { | ||
166 | let devint = dev.parse::<i32>().unwrap(); | ||
167 | if devint >= 1 { | ||
168 | println!("Modlist by FxQnLr v{} (DEV)", env!("CARGO_PKG_VERSION")); | ||
169 | } else { | ||
170 | println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); | ||
171 | } | ||
172 | }, | ||
173 | Err(..) => println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")), | ||
174 | } | ||
175 | std::process::exit(0); | ||
176 | } | ||
177 | |||
178 | pub async fn get_input(config: Cfg, args: Vec<String>) -> MLE<Input> { | 195 | pub async fn get_input(config: Cfg, args: Vec<String>) -> MLE<Input> { |
179 | let input = Input::from(config.clone(), args)?; | 196 | let input = Input::from(config.clone(), args)?; |
180 | 197 | ||
198 | if input.command.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No command specified")); }; | ||
199 | |||
181 | match input.clone().command.unwrap() { | 200 | match input.clone().command.unwrap() { |
182 | Cmd::Mod => check_mod(input, config), | 201 | Cmd::Mod => check_mod(input, config), |
183 | Cmd::List => check_list(input), | 202 | Cmd::List => check_list(input), |
184 | Cmd::Update => check_update(input), | 203 | _ => Ok(input), |
185 | Cmd::Download => check_download(input), | ||
186 | Cmd::Io => check_io(input), | ||
187 | } | 204 | } |
188 | } | 205 | } |
189 | 206 | ||
190 | //Move checks to commands? translate to variables there? | 207 | //Move checks to commands? translate to variables there? |
191 | fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> { | 208 | fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> { |
192 | if input.mod_options.is_none() { | 209 | if input.mod_options.is_none() { |
193 | return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ARGUMENT")); | 210 | return Err(MLError::new(ErrorType::ArgumentError, "No mod option")); |
194 | }; | 211 | }; |
195 | match input.clone().mod_options.unwrap() { | 212 | match input.clone().mod_options.unwrap() { |
196 | //Check for MV if no mod-id on both | 213 | //Check for MV if no mod-id on both |
197 | ModOptions::Add => { | 214 | ModOptions::Add => { |
198 | if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; | 215 | if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; |
199 | if input.list_id.is_none() { println!("NOLIST"); input.list = Some(get_current_list(config.clone())?); }; | 216 | if input.list_id.is_none() { input.list = Some(get_current_list(config.clone())?); }; |
200 | Ok(input) | 217 | Ok(input) |
201 | }, | 218 | }, |
202 | ModOptions::Remove => { | 219 | ModOptions::Remove => { |
203 | if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; | 220 | if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; |
204 | Ok(input) | 221 | Ok(input) |
205 | }, | 222 | }, |
206 | } | 223 | } |
@@ -212,9 +229,13 @@ fn check_list(mut input: Input) -> MLE<Input> { | |||
212 | }; | 229 | }; |
213 | match input.clone().list_options.unwrap() { | 230 | match input.clone().list_options.unwrap() { |
214 | ListOptions::Add => { | 231 | ListOptions::Add => { |
215 | if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_ID")); }; | 232 | if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; |
216 | if input.list_mcversion.is_none() { /*TODO Get latest version */ input.list_mcversion = Some(String::from("1.19.3")) }; | 233 | if input.list_mcversion.is_none() { |
217 | if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_MODLOADER")); }; | 234 | println!("No Minecraft Version specified, defaulting to latest release"); |
235 | //TODO Get latest version | ||
236 | input.list_mcversion = Some(String::from("1.19.3")); | ||
237 | }; | ||
238 | if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); }; | ||
218 | if input.directory.is_none() { input.directory = Some(format!("./downloads/{}", input.clone().list_id.expect("earlier if failed"))) }; | 239 | if input.directory.is_none() { input.directory = Some(format!("./downloads/{}", input.clone().list_id.expect("earlier if failed"))) }; |
219 | Ok(input) | 240 | Ok(input) |
220 | }, | 241 | }, |
@@ -230,18 +251,6 @@ fn check_list(mut input: Input) -> MLE<Input> { | |||
230 | } | 251 | } |
231 | } | 252 | } |
232 | 253 | ||
233 | fn check_update(input: Input) -> MLE<Input> { | ||
234 | Ok(input) | ||
235 | } | ||
236 | |||
237 | fn check_download(input: Input) -> MLE<Input> { | ||
238 | Ok(input) | ||
239 | } | ||
240 | |||
241 | fn check_io(input: Input) -> MLE<Input> { | ||
242 | Ok(input) | ||
243 | } | ||
244 | |||
245 | #[test] | 254 | #[test] |
246 | fn input_from() { | 255 | fn input_from() { |
247 | let config = Cfg::init("modlist.toml").unwrap(); | 256 | let config = Cfg::init("modlist.toml").unwrap(); |
@@ -253,6 +262,10 @@ fn input_from() { | |||
253 | mod_id: None, | 262 | mod_id: None, |
254 | mod_version: None, | 263 | mod_version: None, |
255 | set_version: false, | 264 | set_version: false, |
265 | all_lists: false, | ||
266 | clean: false, | ||
267 | direct_download: false, | ||
268 | delete_old: false, | ||
256 | list: None, | 269 | list: None, |
257 | list_options: Some(ListOptions::Add), | 270 | list_options: Some(ListOptions::Add), |
258 | list_id: Some(String::from("test")), | 271 | list_id: Some(String::from("test")), |
@@ -277,6 +290,10 @@ async fn get_input_test() { | |||
277 | mod_id: Some(String::from("test")), | 290 | mod_id: Some(String::from("test")), |
278 | mod_version: None, | 291 | mod_version: None, |
279 | set_version: false, | 292 | set_version: false, |
293 | all_lists: false, | ||
294 | clean: false, | ||
295 | direct_download: false, | ||
296 | delete_old: false, | ||
280 | list: Some(lists_get(config.clone(), String::from("one")).unwrap()), | 297 | list: Some(lists_get(config.clone(), String::from("one")).unwrap()), |
281 | list_options: None, | 298 | list_options: None, |
282 | list_id: None, | 299 | list_id: None, |
@@ -1,14 +1,14 @@ | |||
1 | //pub mod apis; | 1 | pub mod apis; |
2 | pub mod config; | 2 | pub mod config; |
3 | pub mod commands; | 3 | pub mod commands; |
4 | pub mod input; | 4 | pub mod input; |
5 | pub mod db; | 5 | pub mod db; |
6 | pub mod error; | 6 | pub mod error; |
7 | //pub mod files; | 7 | pub mod files; |
8 | 8 | ||
9 | use std::path::Path; | 9 | use std::path::Path; |
10 | 10 | ||
11 | //pub use apis::*; | 11 | pub use apis::*; |
12 | pub use commands::*; | 12 | pub use commands::*; |
13 | use error::{MLE, ErrorType, MLError}; | 13 | use error::{MLE, ErrorType, MLError}; |
14 | 14 | ||
diff --git a/src/main.rs b/src/main.rs index 39e46e8..10980fb 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::env; | 1 | use std::{env, process}; |
2 | 2 | ||
3 | use modlist::{config::Cfg, input::get_input}; | 3 | use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io}; |
4 | 4 | ||
5 | #[tokio::main] | 5 | #[tokio::main] |
6 | async fn main() { | 6 | async fn main() { |
@@ -11,10 +11,49 @@ async fn main() { | |||
11 | args.pop(); | 11 | args.pop(); |
12 | args.reverse(); | 12 | args.reverse(); |
13 | 13 | ||
14 | match get_input(config, args).await { | 14 | let input = match get_input(config.clone(), args).await { |
15 | Ok(..) => (), | 15 | Ok(i) => i, |
16 | Err(e) => { | 16 | Err(e) => { |
17 | println!("{}", e); | 17 | println!("{}", e); |
18 | process::exit(1); | ||
18 | } | 19 | } |
19 | }; | 20 | }; |
21 | |||
22 | dbg!(&input); | ||
23 | |||
24 | match input.clone().command.unwrap() { | ||
25 | Cmd::Mod => { | ||
26 | Ok(()) | ||
27 | }, | ||
28 | Cmd::List => { | ||
29 | list(config, input).await | ||
30 | }, | ||
31 | Cmd::Update => { | ||
32 | update(config, input).await | ||
33 | }, | ||
34 | Cmd::Download => { | ||
35 | download(config, input).await | ||
36 | }, | ||
37 | Cmd::Io => { | ||
38 | io(config, input).await | ||
39 | }, | ||
40 | Cmd::Version => { | ||
41 | show_version(); | ||
42 | Ok(()) | ||
43 | }, | ||
44 | }.unwrap() | ||
45 | } | ||
46 | |||
47 | fn show_version() { | ||
48 | match std::env::var("DEV") { | ||
49 | Ok(dev) => { | ||
50 | let devint = dev.parse::<i32>().unwrap(); | ||
51 | if devint >= 1 { | ||
52 | println!("Modlist by FxQnLr v{} (DEV)", env!("CARGO_PKG_VERSION")); | ||
53 | } else { | ||
54 | println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); | ||
55 | } | ||
56 | }, | ||
57 | Err(..) => println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")), | ||
58 | } | ||
20 | } | 59 | } |