From a9a55e91ba313c2d30f5cb806aac9c4fceddaf2e Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 21 Dec 2022 10:27:19 +0100 Subject: finished io functionality, some mod add changes --- src/commands/io.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/commands/io.rs') diff --git a/src/commands/io.rs b/src/commands/io.rs index 47991c5..2edb95d 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -34,17 +34,25 @@ impl ExportList { pub async fn io(config: Cfg, input: Input) -> Result<(), Box> { - match input.subcommand.ok_or("INVALID_INPUT")? { - Subcmd::Export => { export(config, input.args)? }, - Subcmd::Import => { import(config).await? }, + match input.subcommand.clone().ok_or("INVALID_INPUT")? { + Subcmd::Export => { export(config, input)? }, + Subcmd::Import => { import(config, input.args).await? }, _ => { }, } Ok(()) } -fn export(config: Cfg, _args: Option>) -> Result<(), Box> { - let list_ids = lists_get_all_ids(config.clone())?; +fn export(config: Cfg, input: Input) -> Result<(), Box> { + let mut list_ids: Vec = vec![]; + if input.all_lists { + list_ids = lists_get_all_ids(config.clone())?; + } else { + let args = input.args.ok_or("NO_ARGS")?; + for arg in args { + list_ids.push(lists_get(config.clone(), arg)?.id); + } + } let mut lists: Vec = vec![]; for list_id in list_ids { lists.push(ExportList::from(config.clone(), String::from(list_id), true)?); @@ -58,9 +66,14 @@ fn export(config: Cfg, _args: Option>) -> Result<(), Box Result<(), Box> { +async fn import(config: Cfg, args: Option>) -> Result<(), Box> { + + let filestr: String = match args { + Some(args) => String::from(&args[0]), + None => String::from("export.toml"), + }; - let mut file = File::open("export.toml")?; + let mut file = File::open(filestr)?; let mut content = String::new(); file.read_to_string(&mut content)?; let export: Export = toml::from_str(&content)?; @@ -70,12 +83,12 @@ async fn import(config: Cfg) -> Result<(), Box> { for exportlist in export.lists { 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")? }; lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?; - //TODO currently workaround, too many requests let mods: Vec<&str> = exportlist.mods.split("|").collect(); + let mut mod_ids = vec![]; for mod_id in mods { - println!("Adding {}", mod_id); - mod_add(config.clone(), mod_id, list.clone(), false).await?; - } + mod_ids.push(String::from(mod_id)); + }; + mod_add(config.clone(), mod_ids, list.clone(), false).await?; } Ok(()) } -- cgit v1.2.3