diff options
author | fxqnlr <[email protected]> | 2023-05-26 17:40:27 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-05-26 17:40:27 +0200 |
commit | 2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0 (patch) | |
tree | cc8f3522670245775e4be7ac2a1e2ad4fd818c8f /src/main.rs | |
parent | d8554e30029bf43dccce72e982784cd01857b0c4 (diff) | |
download | modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.tar modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.tar.gz modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.zip |
added full progress? cargo fmt
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 164 |
1 files changed, 85 insertions, 79 deletions
diff --git a/src/main.rs b/src/main.rs index d03f88a..d9ad6af 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -2,8 +2,8 @@ use clap::{Parser, Subcommand}; | |||
2 | use modlist::{ | 2 | use modlist::{ |
3 | config::Cfg, | 3 | config::Cfg, |
4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, | 4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, |
5 | download, export, get_current_list, import, list_add, list_change, list_remove, list_version, | 5 | download, export, get_current_list, import, list_add, list_change, list_list, list_remove, |
6 | mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, AddMod, | 6 | list_version, mod_add, mod_remove, update, AddMod, IDSelector, List, Modloader, VersionLevel, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | #[derive(Parser)] | 9 | #[derive(Parser)] |
@@ -43,7 +43,7 @@ enum Commands { | |||
43 | /// remove disabled versions | 43 | /// remove disabled versions |
44 | #[arg(short, long)] | 44 | #[arg(short, long)] |
45 | remove: bool, | 45 | remove: bool, |
46 | 46 | ||
47 | /// optional List selection, else default list will be used | 47 | /// optional List selection, else default list will be used |
48 | #[arg(short, long)] | 48 | #[arg(short, long)] |
49 | list: Option<String>, | 49 | list: Option<String>, |
@@ -81,7 +81,7 @@ enum Commands { | |||
81 | /// the list you want to export | 81 | /// the list you want to export |
82 | list: Option<String>, | 82 | list: Option<String>, |
83 | }, | 83 | }, |
84 | Test | 84 | Test, |
85 | } | 85 | } |
86 | 86 | ||
87 | #[derive(Subcommand)] | 87 | #[derive(Subcommand)] |
@@ -160,86 +160,87 @@ async fn main() { | |||
160 | let config = Cfg::init(cli.config).await.unwrap(); | 160 | let config = Cfg::init(cli.config).await.unwrap(); |
161 | 161 | ||
162 | match cli.command { | 162 | match cli.command { |
163 | Commands::Mod { command } => { | 163 | Commands::Mod { command } => match command { |
164 | match command { | 164 | ModCommands::Add { |
165 | ModCommands::Add { | 165 | id, |
166 | id, | 166 | version, |
167 | version, | 167 | list, |
168 | list, | 168 | download, |
169 | download, | 169 | lock, |
170 | lock, | 170 | } => { |
171 | } => { | 171 | let listf = match list { |
172 | let listf = match list { | 172 | Some(list) => lists_get(&config, &list).unwrap(), |
173 | Some(list) => lists_get(&config, &list).unwrap(), | 173 | None => lists_get(&config, &config_get_current_list(&config).unwrap()).unwrap(), |
174 | None => lists_get( | 174 | }; |
175 | &config, | ||
176 | &config_get_current_list(&config).unwrap(), | ||
177 | ) | ||
178 | .unwrap(), | ||
179 | }; | ||
180 | 175 | ||
181 | let marked_id = match version { | 176 | let marked_id = match version { |
182 | true => IDSelector::VersionID(id), | 177 | true => IDSelector::VersionID(id), |
183 | false => IDSelector::ModificationID(id), | 178 | false => IDSelector::ModificationID(id), |
184 | }; | 179 | }; |
185 | 180 | ||
186 | let add_id = AddMod { id: marked_id, set_version: lock }; | 181 | let add_id = AddMod { |
182 | id: marked_id, | ||
183 | set_version: lock, | ||
184 | }; | ||
187 | 185 | ||
188 | mod_add(&config, vec![add_id], listf, download).await | 186 | mod_add(&config, vec![add_id], listf, download).await |
189 | } | ||
190 | ModCommands::Remove { id, list } => { | ||
191 | let listf = match list { | ||
192 | Some(list) => lists_get(&config, &list).unwrap(), | ||
193 | None => lists_get( | ||
194 | &config, | ||
195 | &config_get_current_list(&config).unwrap(), | ||
196 | ) | ||
197 | .unwrap(), | ||
198 | }; | ||
199 | mod_remove(&config, &id, listf) | ||
200 | } | ||
201 | } | 187 | } |
202 | } | 188 | ModCommands::Remove { id, list } => { |
203 | Commands::List { command, force_gameupdate } => { | 189 | let listf = match list { |
204 | match command { | 190 | Some(list) => lists_get(&config, &list).unwrap(), |
205 | ListCommands::Add { | 191 | None => lists_get(&config, &config_get_current_list(&config).unwrap()).unwrap(), |
206 | id, | 192 | }; |
207 | directory, | 193 | mod_remove(&config, &id, &listf) |
208 | modloader, | ||
209 | version, | ||
210 | } => { | ||
211 | let ml = match modloader { | ||
212 | Some(ml) => Modloader::from(&ml).unwrap(), | ||
213 | None => config.defaults.modloader.clone(), | ||
214 | }; | ||
215 | |||
216 | let versions_path = &config.versions; | ||
217 | let ver = match version { | ||
218 | Some(ver) => VersionLevel::from(&ver).get(versions_path, force_gameupdate).await.unwrap(), | ||
219 | None => config.defaults.version.clone().get(versions_path, force_gameupdate).await.unwrap(), | ||
220 | }; | ||
221 | |||
222 | list_add(&config, &id, &ver, &ml, &directory) | ||
223 | } | ||
224 | ListCommands::Remove { id } => list_remove(&config, id), | ||
225 | ListCommands::List => { | ||
226 | list_list(&config) | ||
227 | } | ||
228 | ListCommands::Change { id } => list_change(&config, id), | ||
229 | ListCommands::Version { | ||
230 | id, | ||
231 | version, | ||
232 | download, | ||
233 | remove, | ||
234 | } => list_version(&config, &id, version, download, remove).await, | ||
235 | } | 194 | } |
236 | } | 195 | }, |
196 | Commands::List { | ||
197 | command, | ||
198 | force_gameupdate, | ||
199 | } => match command { | ||
200 | ListCommands::Add { | ||
201 | id, | ||
202 | directory, | ||
203 | modloader, | ||
204 | version, | ||
205 | } => { | ||
206 | let ml = match modloader { | ||
207 | Some(ml) => Modloader::from(&ml).unwrap(), | ||
208 | None => config.defaults.modloader.clone(), | ||
209 | }; | ||
210 | |||
211 | let versions_path = &config.versions; | ||
212 | let ver = match version { | ||
213 | Some(ver) => VersionLevel::from(&ver) | ||
214 | .get(versions_path, force_gameupdate) | ||
215 | .await | ||
216 | .unwrap(), | ||
217 | None => config | ||
218 | .defaults | ||
219 | .version | ||
220 | .clone() | ||
221 | .get(versions_path, force_gameupdate) | ||
222 | .await | ||
223 | .unwrap(), | ||
224 | }; | ||
225 | |||
226 | list_add(&config, &id, &ver, &ml, &directory) | ||
227 | } | ||
228 | ListCommands::Remove { id } => list_remove(&config, &id), | ||
229 | ListCommands::List => list_list(&config), | ||
230 | ListCommands::Change { id } => list_change(&config, &id), | ||
231 | ListCommands::Version { | ||
232 | id, | ||
233 | version, | ||
234 | download, | ||
235 | remove, | ||
236 | } => list_version(&config, &id, version, download, remove).await, | ||
237 | }, | ||
237 | Commands::Update { | 238 | Commands::Update { |
238 | all, | 239 | all, |
239 | download, | 240 | download, |
240 | clean, | 241 | clean, |
241 | remove, | 242 | remove, |
242 | list | 243 | list, |
243 | } => { | 244 | } => { |
244 | let mut liststack: Vec<List> = vec![]; | 245 | let mut liststack: Vec<List> = vec![]; |
245 | if all { | 246 | if all { |
@@ -248,7 +249,7 @@ async fn main() { | |||
248 | liststack.push(lists_get(&config, &id).unwrap()); | 249 | liststack.push(lists_get(&config, &id).unwrap()); |
249 | } | 250 | } |
250 | } else { | 251 | } else { |
251 | let current = match list { | 252 | let current = match list { |
252 | Some(l) => lists_get(&config, &l).unwrap(), | 253 | Some(l) => lists_get(&config, &l).unwrap(), |
253 | None => get_current_list(&config).unwrap(), | 254 | None => get_current_list(&config).unwrap(), |
254 | }; | 255 | }; |
@@ -257,7 +258,12 @@ async fn main() { | |||
257 | 258 | ||
258 | update(&config, liststack, clean, download, remove).await | 259 | update(&config, liststack, clean, download, remove).await |
259 | } | 260 | } |
260 | Commands::Download { all, clean, remove, list } => { | 261 | Commands::Download { |
262 | all, | ||
263 | clean, | ||
264 | remove, | ||
265 | list, | ||
266 | } => { | ||
261 | let mut liststack: Vec<List> = vec![]; | 267 | let mut liststack: Vec<List> = vec![]; |
262 | if all { | 268 | if all { |
263 | let list_ids = lists_get_all_ids(&config).unwrap(); | 269 | let list_ids = lists_get_all_ids(&config).unwrap(); |
@@ -265,15 +271,15 @@ async fn main() { | |||
265 | liststack.push(lists_get(&config, &id).unwrap()); | 271 | liststack.push(lists_get(&config, &id).unwrap()); |
266 | } | 272 | } |
267 | } else { | 273 | } else { |
268 | let current = match list { | 274 | let current = match list { |
269 | Some(l) => lists_get(&config, &l).unwrap(), | 275 | Some(l) => lists_get(&config, &l).unwrap(), |
270 | None => get_current_list(&config).unwrap(), | 276 | None => get_current_list(&config).unwrap(), |
271 | }; | 277 | }; |
272 | liststack.push(current) | 278 | liststack.push(current) |
273 | } | 279 | } |
274 | 280 | ||
275 | download(&config, liststack, clean, remove).await | 281 | download(&config, liststack, clean, remove).await |
276 | }, | 282 | } |
277 | Commands::Import { file, download } => { | 283 | Commands::Import { file, download } => { |
278 | let filestr: String = match file { | 284 | let filestr: String = match file { |
279 | Some(args) => args, | 285 | Some(args) => args, |