From 96b08f4061ab46c5a5fdc25e8e481d2b19b701ec Mon Sep 17 00:00:00 2001 From: dark0dave Date: Sat, 11 Nov 2023 19:26:50 +0000 Subject: [PATCH] feat(subcomponent): Add support for subcomponents Signed-off-by: dark0dave --- Cargo.lock | 8 ++++---- fixtures/test.log | 1 + src/main.rs | 6 +++--- src/mod_component.rs | 26 +++++++++++++++++++++++--- src/utils.rs | 1 + 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72e7e13..f3376ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,9 +67,9 @@ checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "clap" -version = "4.4.7" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" +checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" dependencies = [ "clap_builder", "clap_derive", @@ -77,9 +77,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.7" +version = "4.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" +checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" dependencies = [ "anstream", "anstyle", diff --git a/fixtures/test.log b/fixtures/test.log index a983acf..6ca8684 100644 --- a/fixtures/test.log +++ b/fixtures/test.log @@ -3,3 +3,4 @@ // ~TP2_File~ #language_number #component_number // [Subcomponent Name -> ] Component Name [ : Version] ~TEST_MOD_NAME_1/TEST.TP2~ #0 #0 // test mod one ~TEST_MOD_NAME_2/TEST.TP2~ #0 #0 // test mod two +~TEST_MOD_NAME_3/TEST.TP2~ #0 #0 diff --git a/src/main.rs b/src/main.rs index b93b686..34f564b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,10 +36,10 @@ fn main() { let number_of_mods_found = mods.len(); let mods_to_be_installed = if args.skip_installed { let installed_mods = parse_weidu_log(installed_log_path); - mods.iter() + mods.into_iter() .filter_map(|weidu_mod| { - if !installed_mods.contains(weidu_mod) { - Some(weidu_mod.clone()) + if !installed_mods.contains(&weidu_mod) { + Some(weidu_mod) } else { None } diff --git a/src/mod_component.rs b/src/mod_component.rs index 4f2c9c0..d9d8df5 100644 --- a/src/mod_component.rs +++ b/src/mod_component.rs @@ -10,6 +10,7 @@ pub struct ModComponent { pub name: String, pub lang: String, pub component: String, + pub subcomponent: Option, } impl From for ModComponent { @@ -48,11 +49,18 @@ impl From for ModComponent { .expect("Could not find component") .replace('#', ""); + lang_and_component.next(); + let subcomponent = lang_and_component + .fuse() + .map(|char| char.to_string()) + .reduce(|acc, e| format!("{} {}", acc, e)); + ModComponent { tp_file, name, lang, component, + subcomponent, } } } @@ -93,16 +101,28 @@ mod tests { tp_file: "TEST.TP2".to_string(), name: "test_mod_name_1".to_string(), lang: "0".to_string(), - component: "0".to_string() + component: "0".to_string(), + subcomponent: Some("test mod one".to_string()) }) ); assert_eq!( - logs.last(), + logs.get(1), Some(&ModComponent { tp_file: "TEST.TP2".to_string(), name: "test_mod_name_2".to_string(), lang: "0".to_string(), - component: "0".to_string() + component: "0".to_string(), + subcomponent: Some("test mod two".to_string()) + }) + ); + assert_eq!( + logs.last(), + Some(&ModComponent { + tp_file: "TEST.TP2".to_string(), + name: "test_mod_name_3".to_string(), + lang: "0".to_string(), + component: "0".to_string(), + subcomponent: None }) ); } diff --git a/src/utils.rs b/src/utils.rs index c621fa1..704199d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -81,6 +81,7 @@ mod tests { name: "test_mod_name_1".to_string(), lang: "0".to_string(), component: "0".to_string(), + subcomponent: None, }; let mod_folder = find_mod_folder(&mod_component, Path::new("fixtures/mods"), 3);