From d0d282de34e77263129770ab28b8ec97d115ba72 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 4 Jan 2023 13:41:27 +0100 Subject: started version implementation --- data.db | 0 planmodlist.xopp | Bin 235568 -> 251986 bytes src/commands/list.rs | 12 ++++++++++-- src/db.rs | 13 +++++++++---- src/input.rs | 17 +++++++++++++++-- 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 data.db diff --git a/data.db b/data.db new file mode 100644 index 0000000..e69de29 diff --git a/planmodlist.xopp b/planmodlist.xopp index 78a24c3..f41860e 100644 Binary files a/planmodlist.xopp and b/planmodlist.xopp differ diff --git a/src/commands/list.rs b/src/commands/list.rs index bc9e67e..585efe2 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,6 +1,6 @@ use std::io::{Error, ErrorKind}; -use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get}, Modloader, config::Cfg, input::{Input, Subcmd}}; +use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, Subcmd}}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct List { @@ -10,7 +10,7 @@ pub struct List { pub download_folder: String, } -pub fn list(config: Cfg, input: Input) -> Result<(), Box> { +pub async fn list(config: Cfg, input: Input) -> Result<(), Box> { match input.subcommand.ok_or("")? { Subcmd::Add => { @@ -22,6 +22,9 @@ pub fn list(config: Cfg, input: Input) -> Result<(), Box> Subcmd::Remove => { remove(config, input.args.ok_or("")?) }, + Subcmd::Version => { + version(config, input.args.ok_or("NO_VERSION")?) + } _ => { Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) } @@ -70,3 +73,8 @@ fn remove(config: Cfg, args: Vec) -> Result<(), Box panic!("list arguments should never be zero or lower"), } } + +fn version(config: Cfg, args: Vec) -> Result<(), Box> { + lists_version(config.clone(), config_get_current_list(config.clone())?, String::from(&args[0])) + //update the list & with -- args +} diff --git a/src/db.rs b/src/db.rs index 3f05772..d823018 100644 --- a/src/db.rs +++ b/src/db.rs @@ -32,7 +32,6 @@ pub fn mods_get_all_ids(config: Cfg) -> Result, Box Result Result Result Result<(), Box> { + let data = devdir(format!("{}/data.db", config.data).as_str()); + let connection = Connection::open(data).unwrap(); + + connection.execute("UPDATE lists SET mc_version = ? WHERE id = ?", [version, list_id])?; + Ok(()) +} + pub fn lists_get_all_ids(config: Cfg) -> Result, Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); @@ -510,7 +515,7 @@ pub fn db_setup(config: Cfg) -> Result<(), Box> { "CREATE TABLE 'user_config' ( 'id' TEXT, 'value' TEXT ); CREATE TABLE 'mods' ( 'id' TEXT, 'name' TEXT, 'versions' TEXT ); CREATE TABLE 'lists' ( 'id' TEXT, 'mc_version' TEXT, 'modloader' TEXT, 'download_folder' TEXT ); - INSERT INTO 'user_config' VALUES ( 'db_version', '0.3' ); + INSERT INTO 'user_config' VALUES ( 'db_version', '0.4' ); INSERT INTO 'user_config' VALUES ( 'current_list', '...' )", )?; diff --git a/src/input.rs b/src/input.rs index 09d05a1..d048775 100644 --- a/src/input.rs +++ b/src/input.rs @@ -46,7 +46,18 @@ impl Input { } if version { - println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); + match std::env::var("DEV") { + Ok(dev) => { + let devint = dev.parse::().unwrap(); + if devint >= 1 { + println!("Modlist by FxQnLr v{} (DEV)", env!("CARGO_PKG_VERSION")); + } else { + println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); + } + }, + Err(..) => println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")), + } + std::process::exit(0); } @@ -101,6 +112,7 @@ pub enum Subcmd { Add, Remove, Change, + Version, Export, Import, } @@ -111,6 +123,7 @@ impl Subcmd { "add" => Self::Add, "remove" => Self::Remove, "change" => Self::Change, + "version" => Self::Version, "export" => Self::Export, "import" => Self::Import, _ => return Err(MLError::new(ErrorType::ArgumentError, "SUBCMD_NOT_FOUND")) @@ -132,7 +145,7 @@ pub async fn get_input(config: Cfg) -> Result<(), Box> { modification(config, input).await }, Cmd::List => { - list(config, input) + list(config, input).await }, Cmd::Update => { update(config, input).await -- cgit v1.2.3