diff options
author | fxqnlr <[email protected]> | 2023-01-19 18:37:42 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-01-19 18:37:42 +0100 |
commit | f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 (patch) | |
tree | 21d0c7356b55e9b45517fd9ca874dd3270b6bc3a /src/commands/io.rs | |
parent | be9f74f4fb82b25abd99f7024e0f5eea2691f34f (diff) | |
download | modlist-f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537.tar modlist-f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537.tar.gz modlist-f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537.zip |
input mostly inplemented, mods missing
Diffstat (limited to 'src/commands/io.rs')
-rw-r--r-- | src/commands/io.rs | 30 |
1 files changed, 13 insertions, 17 deletions
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 | } |