From 93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 17 Apr 2023 20:30:16 +0200 Subject: added clap cli, modified (basically) all user interface functions; changed some functions to easier string handling --- src/commands/io.rs | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'src/commands/io.rs') 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; use std::io::prelude::*; use serde::{Serialize, Deserialize}; -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}; +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}; #[derive(Debug, Serialize, Deserialize)] struct Export { @@ -32,22 +32,12 @@ impl ExportList { } } -pub async fn io(config: Cfg, input: Input) -> MLE<()> { - - match input.clone().io_options.unwrap() { - IoOptions::Export => { export(config, input)? }, - IoOptions::Import => { import(config, input).await? }, - } - - Ok(()) -} - -fn export(config: Cfg, input: Input) -> MLE<()> { +pub fn export(config: Cfg, list: Option) -> MLE<()> { let mut list_ids: Vec = vec![]; - if input.all_lists { + if list.is_none() { list_ids = lists_get_all_ids(config.clone())?; } else { - list_ids.push(lists_get(config.clone(), input.list.unwrap().id)?.id); + list_ids.push(lists_get(config.clone(), list.unwrap())?.id); } let mut lists: Vec = vec![]; for list_id in list_ids { @@ -64,14 +54,9 @@ fn export(config: Cfg, input: Input) -> MLE<()> { Ok(()) } -async fn import(config: Cfg, input: Input) -> MLE<()> { +pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE<()> { - let filestr: String = match input.file { - Some(args) => args, - None => devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str()), - }; - - let mut file = File::open(filestr)?; + let mut file = File::open(file_str)?; let mut content = String::new(); file.read_to_string(&mut content)?; let export: Export = toml::from_str(&content)?; @@ -86,7 +71,7 @@ async fn import(config: Cfg, input: Input) -> MLE<()> { }; //TODO impl set_version and good direct download //TODO impl all at once, dafuck - mods_add(config.clone(), mod_ids, list, input.direct_download, false).await?; + mod_add(config.clone(), mod_ids, list, direct_download, false).await?; } Ok(()) } -- cgit v1.2.3