summaryrefslogtreecommitdiff
path: root/src/commands/modification.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-04-17 20:30:16 +0200
committerfxqnlr <[email protected]>2023-04-17 20:30:16 +0200
commit93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba (patch)
tree043adeff1c117f3f0e4fe7bffc472c299e01d642 /src/commands/modification.rs
parent77d2ac94534b12300b5b7eff6e28023d815708eb (diff)
downloadmodlist-93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba.tar
modlist-93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba.tar.gz
modlist-93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba.zip
added clap cli, modified (basically) all user interface functions;
changed some functions to easier string handling
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r--src/commands/modification.rs44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs
index 31e50af..454e148 100644
--- a/src/commands/modification.rs
+++ b/src/commands/modification.rs
@@ -1,4 +1,4 @@
1use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, ModOptions}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; 1use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}};
2 2
3#[derive(Debug, Clone, PartialEq, Eq)] 3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum IDSelector { 4pub enum IDSelector {
@@ -6,24 +6,6 @@ pub enum IDSelector {
6 VersionID(String) 6 VersionID(String)
7} 7}
8 8
9pub async fn modification(config: Cfg, input: Input) -> MLE<()> {
10 match input.clone().mod_options.ok_or("").unwrap() {
11 ModOptions::Add => {
12 add(config, input).await
13 },
14 ModOptions::Remove => {
15 remove(config, input)
16 },
17 }
18}
19
20async fn add(config: Cfg, input: Input) -> MLE<()> {
21
22 mods_add(config, vec![input.mod_id.unwrap()], input.list.unwrap(), input.direct_download, input.set_version).await?;
23
24 Ok(())
25}
26
27#[derive(Debug, Clone)] 9#[derive(Debug, Clone)]
28pub struct ProjectInfo { 10pub struct ProjectInfo {
29 pub mod_id: String, 11 pub mod_id: String,
@@ -34,7 +16,7 @@ pub struct ProjectInfo {
34 pub download_link: String, 16 pub download_link: String,
35} 17}
36 18
37pub async fn mods_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_download: bool, set_version: bool) -> MLE<()> { 19pub async fn mod_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_download: bool, set_version: bool) -> MLE<()> {
38 println!("Add mods to {}", list.id); 20 println!("Add mods to {}", list.id);
39 println!(" └Add mods:"); 21 println!(" └Add mods:");
40 22
@@ -156,22 +138,24 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<String>) -> MLE<Vec<ProjectInfo>
156 Ok(projectinfo) 138 Ok(projectinfo)
157} 139}
158 140
159fn remove(config: Cfg, input: Input) -> MLE<()> { 141/// Remove mod from a list
160 142/// # Arguments
161 let id = match input.clone().mod_id.unwrap() { 143///
162 IDSelector::ModificationID(id) => id, 144/// * `config` - config struct
163 IDSelector::VersionID(..) => return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ID")), 145/// * `id` - name, slug or id of the mod
164 }; 146/// * `list` - List struct
147pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> {
165 148
166 let mod_id = mods_get_id(&config.data, &id)?; 149 let mod_id = mods_get_id(&config.data, id)?;
167 150
168 let version = userlist_get_current_version(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; 151 let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?;
169 152
170 userlist_remove(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; 153 userlist_remove(config.clone(), &list.id, &mod_id)?;
171 delete_version(input.list.unwrap(), version)?; 154 delete_version(list, version)?;
172 155
173 let list_ids = lists_get_all_ids(config.clone())?; 156 let list_ids = lists_get_all_ids(config.clone())?;
174 157
158 // Remove mod from main list if not used elsewhere
175 let mut mod_used = false; 159 let mut mod_used = false;
176 for id in list_ids { 160 for id in list_ids {
177 let mods = userlist_get_all_ids(config.clone(), id)?; 161 let mods = userlist_get_all_ids(config.clone(), id)?;