summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs206
1 files changed, 111 insertions, 95 deletions
diff --git a/src/main.rs b/src/main.rs
index 31a320b..5d60a17 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,8 +2,9 @@ use clap::{Parser, Subcommand};
2use modlist::{ 2use 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,
6 mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, AddMod, 6 list_list, list_remove, list_version, mod_add, mod_remove, update, AddMod,
7 IDSelector, List, Modloader, VersionLevel,
7}; 8};
8 9
9#[derive(Parser)] 10#[derive(Parser)]
@@ -15,10 +16,6 @@ struct Cli {
15 /// config file path 16 /// config file path
16 #[arg(short, long)] 17 #[arg(short, long)]
17 config: Option<String>, 18 config: Option<String>,
18
19 /// Force GameVersion update
20 #[arg(long)]
21 force_gameupdate: bool,
22} 19}
23 20
24#[derive(Subcommand)] 21#[derive(Subcommand)]
@@ -30,6 +27,10 @@ enum Commands {
30 List { 27 List {
31 #[command(subcommand)] 28 #[command(subcommand)]
32 command: ListCommands, 29 command: ListCommands,
30
31 /// Force GameVersion update
32 #[arg(long)]
33 force_gameupdate: bool,
33 }, 34 },
34 Download { 35 Download {
35 /// download all lists 36 /// download all lists
@@ -43,7 +44,7 @@ enum Commands {
43 /// remove disabled versions 44 /// remove disabled versions
44 #[arg(short, long)] 45 #[arg(short, long)]
45 remove: bool, 46 remove: bool,
46 47
47 /// optional List selection, else default list will be used 48 /// optional List selection, else default list will be used
48 #[arg(short, long)] 49 #[arg(short, long)]
49 list: Option<String>, 50 list: Option<String>,
@@ -81,7 +82,7 @@ enum Commands {
81 /// the list you want to export 82 /// the list you want to export
82 list: Option<String>, 83 list: Option<String>,
83 }, 84 },
84 Test 85 Test,
85} 86}
86 87
87#[derive(Subcommand)] 88#[derive(Subcommand)]
@@ -160,119 +161,134 @@ async fn main() {
160 let config = Cfg::init(cli.config).await.unwrap(); 161 let config = Cfg::init(cli.config).await.unwrap();
161 162
162 match cli.command { 163 match cli.command {
163 Commands::Mod { command } => { 164 Commands::Mod { command } => match command {
164 match command { 165 ModCommands::Add {
165 #[allow(unused_variables)] 166 id,
166 ModCommands::Add { 167 version,
167 id, 168 list,
168 version, 169 download,
169 list, 170 lock,
170 download, 171 } => {
171 lock, 172 let listf = match list {
172 } => { 173 Some(list) => lists_get(&config, &list).unwrap(),
173 let listf = match list { 174 None => lists_get(
174 Some(list) => lists_get(config.clone(), list).unwrap(), 175 &config,
175 None => lists_get( 176 &config_get_current_list(&config).unwrap(),
176 config.clone(), 177 )
177 config_get_current_list(config.clone()).unwrap(), 178 .unwrap(),
178 ) 179 };
179 .unwrap(),
180 };
181 180
182 let marked_id = match version { 181 let marked_id = match version {
183 true => IDSelector::VersionID(id), 182 true => IDSelector::VersionID(id),
184 false => IDSelector::ModificationID(id), 183 false => IDSelector::ModificationID(id),
185 }; 184 };
186 185
187 let add_id = AddMod { id: marked_id, set_version: lock }; 186 let add_id = AddMod {
187 id: marked_id,
188 set_version: lock,
189 };
188 190
189 mod_add(config, vec![add_id], listf, download).await 191 mod_add(&config, vec![add_id], listf, download).await
190 }
191 ModCommands::Remove { id, list } => {
192 let listf = match list {
193 Some(list) => lists_get(config.clone(), list).unwrap(),
194 None => lists_get(
195 config.clone(),
196 config_get_current_list(config.clone()).unwrap(),
197 )
198 .unwrap(),
199 };
200 mod_remove(config, &id, listf)
201 }
202 } 192 }
203 } 193 ModCommands::Remove { id, list } => {
204 Commands::List { command } => { 194 let listf = match list {
205 match command { 195 Some(list) => lists_get(&config, &list).unwrap(),
206 ListCommands::Add { 196 None => lists_get(
207 id, 197 &config,
208 directory, 198 &config_get_current_list(&config).unwrap(),
209 modloader, 199 )
210 version, 200 .unwrap(),
211 } => { 201 };
212 let ml = match modloader { 202 mod_remove(&config, &id, &listf)
213 Some(ml) => Modloader::from(&ml).unwrap(),
214 None => config.clone().defaults.modloader,
215 };
216
217 let versions_path = &config.versions;
218 let ver = match version {
219 Some(ver) => VersionLevel::from(&ver).get(versions_path, cli.force_gameupdate).await.unwrap(),
220 None => config.clone().defaults.version.get(versions_path, cli.force_gameupdate).await.unwrap(),
221 };
222
223 list_add(config, id, ver, ml, directory)
224 }
225 ListCommands::Remove { id } => list_remove(config, id),
226 ListCommands::List => {
227 list_list(config)
228 }
229 ListCommands::Change { id } => list_change(config, id),
230 ListCommands::Version {
231 id,
232 version,
233 download,
234 remove,
235 } => list_version(config, id, version, download, remove).await,
236 } 203 }
237 } 204 },
205 Commands::List {
206 command,
207 force_gameupdate,
208 } => match command {
209 ListCommands::Add {
210 id,
211 directory,
212 modloader,
213 version,
214 } => {
215 let ml = match modloader {
216 Some(ml) => Modloader::from(&ml).unwrap(),
217 None => config.defaults.modloader.clone(),
218 };
219
220 let versions_path = &config.versions;
221 let ver = match version {
222 Some(ver) => VersionLevel::from(&ver)
223 .get(versions_path, force_gameupdate)
224 .await
225 .unwrap(),
226 None => config
227 .defaults
228 .version
229 .clone()
230 .get(versions_path, force_gameupdate)
231 .await
232 .unwrap(),
233 };
234
235 list_add(&config, &id, &ver, &ml, &directory)
236 }
237 ListCommands::Remove { id } => list_remove(&config, &id),
238 ListCommands::List => list_list(&config),
239 ListCommands::Change { id } => list_change(&config, &id),
240 ListCommands::Version {
241 id,
242 version,
243 download,
244 remove,
245 } => list_version(&config, &id, version, download, remove).await,
246 },
238 Commands::Update { 247 Commands::Update {
239 all, 248 all,
240 download, 249 download,
241 clean, 250 clean,
242 remove, 251 remove,
243 list 252 list,
244 } => { 253 } => {
245 let mut liststack: Vec<List> = vec![]; 254 let mut liststack: Vec<List> = vec![];
246 if all { 255 if all {
247 let list_ids = lists_get_all_ids(config.clone()).unwrap(); 256 let list_ids = lists_get_all_ids(&config).unwrap();
248 for id in list_ids { 257 for id in list_ids {
249 liststack.push(lists_get(config.clone(), id).unwrap()); 258 liststack.push(lists_get(&config, &id).unwrap());
250 } 259 }
251 } else { 260 } else {
252 let current = match list { 261 let current = match list {
253 Some(l) => lists_get(config.clone(), l).unwrap(), 262 Some(l) => lists_get(&config, &l).unwrap(),
254 None => get_current_list(config.clone()).unwrap(), 263 None => get_current_list(&config).unwrap(),
255 }; 264 };
256 liststack.push(current) 265 liststack.push(current)
257 } 266 }
258 update(config, liststack, clean, download, remove).await 267
268 update(&config, liststack, clean, download, remove).await
259 } 269 }
260 Commands::Download { all, clean, remove, list } => { 270 Commands::Download {
271 all,
272 clean,
273 remove,
274 list,
275 } => {
261 let mut liststack: Vec<List> = vec![]; 276 let mut liststack: Vec<List> = vec![];
262 if all { 277 if all {
263 let list_ids = lists_get_all_ids(config.clone()).unwrap(); 278 let list_ids = lists_get_all_ids(&config).unwrap();
264 for id in list_ids { 279 for id in list_ids {
265 liststack.push(lists_get(config.clone(), id).unwrap()); 280 liststack.push(lists_get(&config, &id).unwrap());
266 } 281 }
267 } else { 282 } else {
268 let current = match list { 283 let current = match list {
269 Some(l) => lists_get(config.clone(), l).unwrap(), 284 Some(l) => lists_get(&config, &l).unwrap(),
270 None => get_current_list(config.clone()).unwrap(), 285 None => get_current_list(&config).unwrap(),
271 }; 286 };
272 liststack.push(current) 287 liststack.push(current)
273 } 288 }
274 download(config, liststack, clean, remove).await 289
275 }, 290 download(&config, liststack, clean, remove).await
291 }
276 Commands::Import { file, download } => { 292 Commands::Import { file, download } => {
277 let filestr: String = match file { 293 let filestr: String = match file {
278 Some(args) => args, 294 Some(args) => args,
@@ -284,9 +300,9 @@ async fn main() {
284 .unwrap(), 300 .unwrap(),
285 }; 301 };
286 302
287 import(config, filestr, download).await 303 import(&config, &filestr, download).await
288 } 304 }
289 Commands::Export { list } => export(config, list), 305 Commands::Export { list } => export(&config, list),
290 Commands::Test => Ok(()), 306 Commands::Test => Ok(()),
291 } 307 }
292 .unwrap(); 308 .unwrap();