From f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Jan 2023 18:37:42 +0100 Subject: input mostly inplemented, mods missing --- src/commands/io.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/commands/io.rs') 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; use std::io::prelude::*; use serde::{Serialize, Deserialize}; -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}; +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}; #[derive(Debug, Serialize, Deserialize)] struct Export { @@ -19,7 +19,7 @@ struct ExportList { } impl ExportList { - pub fn from(config: Cfg, list_id: String, download: bool) -> Result> { + pub fn from(config: Cfg, list_id: String, download: bool) -> MLE { let list = lists_get(config.clone(), String::from(&list_id))?; @@ -32,26 +32,22 @@ impl ExportList { } } -pub async fn io(config: Cfg, input: Input) -> Result<(), Box> { +pub async fn io(config: Cfg, input: Input) -> MLE<()> { - match input.subcommand.clone().ok_or("INVALID_INPUT")? { - Subcmd::Export => { export(config, input)? }, - Subcmd::Import => { import(config, input.args).await? }, - _ => { }, + match input.clone().io_options.unwrap() { + IoOptions::Export => { export(config, input)? }, + IoOptions::Import => { import(config, input).await? }, } Ok(()) } -fn export(config: Cfg, input: Input) -> Result<(), Box> { +fn export(config: Cfg, input: Input) -> MLE<()> { 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); - } + list_ids.push(lists_get(config.clone(), input.list.unwrap().id)?.id); } let mut lists: Vec = vec![]; for list_id in list_ids { @@ -68,10 +64,10 @@ fn export(config: Cfg, input: Input) -> Result<(), Box> { Ok(()) } -async fn import(config: Cfg, args: Option>) -> Result<(), Box> { +async fn import(config: Cfg, input: Input) -> MLE<()> { - let filestr: String = match args { - Some(args) => String::from(&args[0]), + let filestr: String = match input.file { + Some(args) => String::from(args), None => String::from(devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str())), }; @@ -83,14 +79,14 @@ async fn import(config: Cfg, args: Option>) -> Result<(), Box = exportlist.mods.split("|").collect(); let mut mod_ids = vec![]; for mod_id in mods { mod_ids.push(String::from(mod_id)); }; - mod_add(config.clone(), mod_ids, list.clone(), false).await?; + //mod_add(config.clone(), mod_ids, list.clone(), false).await?; } Ok(()) } -- cgit v1.2.3