summaryrefslogtreecommitdiff
path: root/src/commands/io.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/io.rs')
-rw-r--r--src/commands/io.rs35
1 files changed, 24 insertions, 11 deletions
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 {
34 34
35pub async fn io(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { 35pub async fn io(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
36 36
37 match input.subcommand.ok_or("INVALID_INPUT")? { 37 match input.subcommand.clone().ok_or("INVALID_INPUT")? {
38 Subcmd::Export => { export(config, input.args)? }, 38 Subcmd::Export => { export(config, input)? },
39 Subcmd::Import => { import(config).await? }, 39 Subcmd::Import => { import(config, input.args).await? },
40 _ => { }, 40 _ => { },
41 } 41 }
42 42
43 Ok(()) 43 Ok(())
44} 44}
45 45
46fn export(config: Cfg, _args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { 46fn export(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
47 let list_ids = lists_get_all_ids(config.clone())?; 47 let mut list_ids: Vec<String> = vec![];
48 if input.all_lists {
49 list_ids = lists_get_all_ids(config.clone())?;
50 } else {
51 let args = input.args.ok_or("NO_ARGS")?;
52 for arg in args {
53 list_ids.push(lists_get(config.clone(), arg)?.id);
54 }
55 }
48 let mut lists: Vec<ExportList> = vec![]; 56 let mut lists: Vec<ExportList> = vec![];
49 for list_id in list_ids { 57 for list_id in list_ids {
50 lists.push(ExportList::from(config.clone(), String::from(list_id), true)?); 58 lists.push(ExportList::from(config.clone(), String::from(list_id), true)?);
@@ -58,9 +66,14 @@ fn export(config: Cfg, _args: Option<Vec<String>>) -> Result<(), Box<dyn std::er
58 Ok(()) 66 Ok(())
59} 67}
60 68
61async fn import(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { 69async fn import(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> {
70
71 let filestr: String = match args {
72 Some(args) => String::from(&args[0]),
73 None => String::from("export.toml"),
74 };
62 75
63 let mut file = File::open("export.toml")?; 76 let mut file = File::open(filestr)?;
64 let mut content = String::new(); 77 let mut content = String::new();
65 file.read_to_string(&mut content)?; 78 file.read_to_string(&mut content)?;
66 let export: Export = toml::from_str(&content)?; 79 let export: Export = toml::from_str(&content)?;
@@ -70,12 +83,12 @@ async fn import(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
70 for exportlist in export.lists { 83 for exportlist in export.lists {
71 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")? }; 84 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")? };
72 lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?; 85 lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?;
73 //TODO currently workaround, too many requests
74 let mods: Vec<&str> = exportlist.mods.split("|").collect(); 86 let mods: Vec<&str> = exportlist.mods.split("|").collect();
87 let mut mod_ids = vec![];
75 for mod_id in mods { 88 for mod_id in mods {
76 println!("Adding {}", mod_id); 89 mod_ids.push(String::from(mod_id));
77 mod_add(config.clone(), mod_id, list.clone(), false).await?; 90 };
78 } 91 mod_add(config.clone(), mod_ids, list.clone(), false).await?;
79 } 92 }
80 Ok(()) 93 Ok(())
81} 94}