summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-01-04 13:41:27 +0100
committerFxQnLr <[email protected]>2023-01-04 13:41:27 +0100
commitd0d282de34e77263129770ab28b8ec97d115ba72 (patch)
tree610ef23afb27b37d6815859bece24cff78c284ef
parent9365747f8da3185670780f013d059b3271950f75 (diff)
downloadmodlist-d0d282de34e77263129770ab28b8ec97d115ba72.tar
modlist-d0d282de34e77263129770ab28b8ec97d115ba72.tar.gz
modlist-d0d282de34e77263129770ab28b8ec97d115ba72.zip
started version implementation
-rw-r--r--data.db0
-rw-r--r--planmodlist.xoppbin235568 -> 251986 bytes
-rw-r--r--src/commands/list.rs12
-rw-r--r--src/db.rs13
-rw-r--r--src/input.rs17
5 files changed, 34 insertions, 8 deletions
diff --git a/data.db b/data.db
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/data.db
diff --git a/planmodlist.xopp b/planmodlist.xopp
index 78a24c3..f41860e 100644
--- a/planmodlist.xopp
+++ b/planmodlist.xopp
Binary files 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 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2 2
3use 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}}; 3use 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}};
4 4
5#[derive(Debug, Clone, PartialEq, Eq)] 5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct List { 6pub struct List {
@@ -10,7 +10,7 @@ pub struct List {
10 pub download_folder: String, 10 pub download_folder: String,
11} 11}
12 12
13pub fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { 13pub async fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
14 14
15 match input.subcommand.ok_or("")? { 15 match input.subcommand.ok_or("")? {
16 Subcmd::Add => { 16 Subcmd::Add => {
@@ -22,6 +22,9 @@ pub fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>>
22 Subcmd::Remove => { 22 Subcmd::Remove => {
23 remove(config, input.args.ok_or("")?) 23 remove(config, input.args.ok_or("")?)
24 }, 24 },
25 Subcmd::Version => {
26 version(config, input.args.ok_or("NO_VERSION")?)
27 }
25 _ => { 28 _ => {
26 Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) 29 Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND")))
27 } 30 }
@@ -70,3 +73,8 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro
70 _ => panic!("list arguments should never be zero or lower"), 73 _ => panic!("list arguments should never be zero or lower"),
71 } 74 }
72} 75}
76
77fn version(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
78 lists_version(config.clone(), config_get_current_list(config.clone())?, String::from(&args[0]))
79 //update the list & with -- args
80}
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<Vec<String>, Box<dyn std::error::
32 })?; 32 })?;
33 33
34 for id in id_iter { 34 for id in id_iter {
35 //println!("Found id {:?}", id.as_ref().unwrap());
36 mods.push(id?); 35 mods.push(id?);
37 } 36 }
38 37
@@ -53,7 +52,6 @@ pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::err
53 })?; 52 })?;
54 53
55 for id in id_iter { 54 for id in id_iter {
56 //println!("Found id {:?}", id.as_ref().unwrap());
57 mod_id = id?; 55 mod_id = id?;
58 }; 56 };
59 57
@@ -74,7 +72,6 @@ pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::err
74 })?; 72 })?;
75 73
76 for name in name_iter { 74 for name in name_iter {
77 //println!("Found id {:?}", id.as_ref().unwrap());
78 mod_name = name?; 75 mod_name = name?;
79 }; 76 };
80 77
@@ -394,6 +391,14 @@ pub fn lists_get(config: Cfg, list_id: String) -> Result<List, Box<dyn std::erro
394 Ok(list) 391 Ok(list)
395} 392}
396 393
394pub fn lists_version(config: Cfg, list_id: String, version: String) -> Result<(), Box<dyn std::error::Error>> {
395 let data = devdir(format!("{}/data.db", config.data).as_str());
396 let connection = Connection::open(data).unwrap();
397
398 connection.execute("UPDATE lists SET mc_version = ? WHERE id = ?", [version, list_id])?;
399 Ok(())
400}
401
397pub fn lists_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { 402pub fn lists_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> {
398 let data = devdir(format!("{}/data.db", config.data).as_str()); 403 let data = devdir(format!("{}/data.db", config.data).as_str());
399 let connection = Connection::open(data).unwrap(); 404 let connection = Connection::open(data).unwrap();
@@ -510,7 +515,7 @@ pub fn db_setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
510 "CREATE TABLE 'user_config' ( 'id' TEXT, 'value' TEXT ); 515 "CREATE TABLE 'user_config' ( 'id' TEXT, 'value' TEXT );
511 CREATE TABLE 'mods' ( 'id' TEXT, 'name' TEXT, 'versions' TEXT ); 516 CREATE TABLE 'mods' ( 'id' TEXT, 'name' TEXT, 'versions' TEXT );
512 CREATE TABLE 'lists' ( 'id' TEXT, 'mc_version' TEXT, 'modloader' TEXT, 'download_folder' TEXT ); 517 CREATE TABLE 'lists' ( 'id' TEXT, 'mc_version' TEXT, 'modloader' TEXT, 'download_folder' TEXT );
513 INSERT INTO 'user_config' VALUES ( 'db_version', '0.3' ); 518 INSERT INTO 'user_config' VALUES ( 'db_version', '0.4' );
514 INSERT INTO 'user_config' VALUES ( 'current_list', '...' )", 519 INSERT INTO 'user_config' VALUES ( 'current_list', '...' )",
515 )?; 520 )?;
516 521
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 {
46 } 46 }
47 47
48 if version { 48 if version {
49 println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); 49 match std::env::var("DEV") {
50 Ok(dev) => {
51 let devint = dev.parse::<i32>().unwrap();
52 if devint >= 1 {
53 println!("Modlist by FxQnLr v{} (DEV)", env!("CARGO_PKG_VERSION"));
54 } else {
55 println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION"));
56 }
57 },
58 Err(..) => println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")),
59 }
60
50 std::process::exit(0); 61 std::process::exit(0);
51 } 62 }
52 63
@@ -101,6 +112,7 @@ pub enum Subcmd {
101 Add, 112 Add,
102 Remove, 113 Remove,
103 Change, 114 Change,
115 Version,
104 Export, 116 Export,
105 Import, 117 Import,
106} 118}
@@ -111,6 +123,7 @@ impl Subcmd {
111 "add" => Self::Add, 123 "add" => Self::Add,
112 "remove" => Self::Remove, 124 "remove" => Self::Remove,
113 "change" => Self::Change, 125 "change" => Self::Change,
126 "version" => Self::Version,
114 "export" => Self::Export, 127 "export" => Self::Export,
115 "import" => Self::Import, 128 "import" => Self::Import,
116 _ => return Err(MLError::new(ErrorType::ArgumentError, "SUBCMD_NOT_FOUND")) 129 _ => return Err(MLError::new(ErrorType::ArgumentError, "SUBCMD_NOT_FOUND"))
@@ -132,7 +145,7 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
132 modification(config, input).await 145 modification(config, input).await
133 }, 146 },
134 Cmd::List => { 147 Cmd::List => {
135 list(config, input) 148 list(config, input).await
136 }, 149 },
137 Cmd::Update => { 150 Cmd::Update => {
138 update(config, input).await 151 update(config, input).await