diff options
Diffstat (limited to 'src/commands/io.rs')
-rw-r--r-- | src/commands/io.rs | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/commands/io.rs b/src/commands/io.rs index a3d056f..5de8dd1 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, IoOptions}, db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, List, devdir, error::MLE, mods_add, IDSelector}; | 5 | use crate::{db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, List, devdir, error::MLE, mod_add, IDSelector}; |
6 | 6 | ||
7 | #[derive(Debug, Serialize, Deserialize)] | 7 | #[derive(Debug, Serialize, Deserialize)] |
8 | struct Export { | 8 | struct Export { |
@@ -32,22 +32,12 @@ impl ExportList { | |||
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | pub async fn io(config: Cfg, input: Input) -> MLE<()> { | 35 | pub fn export(config: Cfg, list: Option<String>) -> MLE<()> { |
36 | |||
37 | match input.clone().io_options.unwrap() { | ||
38 | IoOptions::Export => { export(config, input)? }, | ||
39 | IoOptions::Import => { import(config, input).await? }, | ||
40 | } | ||
41 | |||
42 | Ok(()) | ||
43 | } | ||
44 | |||
45 | fn export(config: Cfg, input: Input) -> MLE<()> { | ||
46 | let mut list_ids: Vec<String> = vec![]; | 36 | let mut list_ids: Vec<String> = vec![]; |
47 | if input.all_lists { | 37 | if list.is_none() { |
48 | list_ids = lists_get_all_ids(config.clone())?; | 38 | list_ids = lists_get_all_ids(config.clone())?; |
49 | } else { | 39 | } else { |
50 | list_ids.push(lists_get(config.clone(), input.list.unwrap().id)?.id); | 40 | list_ids.push(lists_get(config.clone(), list.unwrap())?.id); |
51 | } | 41 | } |
52 | let mut lists: Vec<ExportList> = vec![]; | 42 | let mut lists: Vec<ExportList> = vec![]; |
53 | for list_id in list_ids { | 43 | for list_id in list_ids { |
@@ -64,14 +54,9 @@ fn export(config: Cfg, input: Input) -> MLE<()> { | |||
64 | Ok(()) | 54 | Ok(()) |
65 | } | 55 | } |
66 | 56 | ||
67 | async fn import(config: Cfg, input: Input) -> MLE<()> { | 57 | pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE<()> { |
68 | 58 | ||
69 | let filestr: String = match input.file { | 59 | let mut file = File::open(file_str)?; |
70 | Some(args) => args, | ||
71 | None => devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str()), | ||
72 | }; | ||
73 | |||
74 | let mut file = File::open(filestr)?; | ||
75 | let mut content = String::new(); | 60 | let mut content = String::new(); |
76 | file.read_to_string(&mut content)?; | 61 | file.read_to_string(&mut content)?; |
77 | let export: Export = toml::from_str(&content)?; | 62 | let export: Export = toml::from_str(&content)?; |
@@ -86,7 +71,7 @@ async fn import(config: Cfg, input: Input) -> MLE<()> { | |||
86 | }; | 71 | }; |
87 | //TODO impl set_version and good direct download | 72 | //TODO impl set_version and good direct download |
88 | //TODO impl all at once, dafuck | 73 | //TODO impl all at once, dafuck |
89 | mods_add(config.clone(), mod_ids, list, input.direct_download, false).await?; | 74 | mod_add(config.clone(), mod_ids, list, direct_download, false).await?; |
90 | } | 75 | } |
91 | Ok(()) | 76 | Ok(()) |
92 | } | 77 | } |