diff --git a/Cargo.lock b/Cargo.lock index 87b64fe..bb312ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -56,9 +56,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.76" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59d2a3357dde987206219e78ecfbbb6e8dad06cbb65292758d3270e6254f7355" +checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" [[package]] name = "approx" @@ -113,7 +113,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -124,7 +124,7 @@ checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -263,7 +263,7 @@ dependencies = [ "iana-time-zone", "num-traits", "serde", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -347,21 +347,20 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.16" +version = "0.9.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2fe95351b870527a5d09bf563ed3c97c0cffb87cf1c78a591bf48bb218d9aa" +checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset", ] [[package]] name = "crossbeam-utils" -version = "0.8.17" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" +checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" dependencies = [ "cfg-if", ] @@ -440,9 +439,9 @@ checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] @@ -550,9 +549,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -565,9 +564,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -575,15 +574,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -592,38 +591,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -815,9 +814,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1086,18 +1085,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "meval" @@ -1310,9 +1300,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -1401,7 +1391,7 @@ dependencies = [ "libc", "redox_syscall 0.4.1", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -1783,7 +1773,7 @@ dependencies = [ [[package]] name = "rust-workspace" -version = "0.7.20" +version = "0.7.21" dependencies = [ "cargo-husky", "ciborium", @@ -1951,9 +1941,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.12" +version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +checksum = "8bb1879ea93538b78549031e2d54da3e901fd7e75f2e4dc758d760937b123d10" dependencies = [ "serde", ] @@ -1966,7 +1956,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -2182,9 +2172,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" dependencies = [ "proc-macro2", "quote", @@ -2193,9 +2183,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.0" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68492e7268037de59ae153d7efb79546cf94a18a9548235420d3d8d2436b4b1" +checksum = "ba2dbd2894d23b2d78dae768d85e323b557ac3ac71a5d917a31536d8f77ebada" dependencies = [ "cfg-if", "core-foundation-sys", @@ -2250,22 +2240,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "83a48fd946b02c0a526b2e9481c8e2a17755e47039164a86c4070446e3a4614d" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -2339,7 +2329,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -2392,7 +2382,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] [[package]] @@ -2578,7 +2568,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", "wasm-bindgen-shared", ] @@ -2612,7 +2602,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2684,21 +2674,21 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ "windows-core", - "windows-targets", + "windows-targets 0.52.0", ] [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets", + "windows-targets 0.52.0", ] [[package]] @@ -2707,7 +2697,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2716,13 +2706,28 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] @@ -2731,42 +2736,84 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + [[package]] name = "winreg" version = "0.50.0" @@ -2803,5 +2850,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.42", + "syn 2.0.43", ] diff --git a/Cargo.toml b/Cargo.toml index 5c35fa4..41a5c51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust-workspace" -version = "0.7.20" +version = "0.7.21" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -11,7 +11,7 @@ hyper = { version = "0.14", features = ["full"] } tokio = { version = "1.35.1", features = ["full"] } meval = "0.2" rand = "0.8.5" -sysinfo = "0.30.0" +sysinfo = "0.30.3" # ML Packages for Model Training linfa = "0.7.0" linfa-logistic = { version = "0.7.0", features = ["serde"] } diff --git a/src/data_pipeline/artifact/config/mod.rs b/src/data_pipeline/artifact/configuration/mod.rs similarity index 100% rename from src/data_pipeline/artifact/config/mod.rs rename to src/data_pipeline/artifact/configuration/mod.rs diff --git a/src/data_pipeline/artifact/mod.rs b/src/data_pipeline/artifact/mod.rs index 0755a3b..704d931 100644 --- a/src/data_pipeline/artifact/mod.rs +++ b/src/data_pipeline/artifact/mod.rs @@ -3,7 +3,7 @@ use colored::Colorize; use std::fs; -mod config; +mod configuration; mod create_artifact; mod restore_artifact; @@ -39,9 +39,9 @@ impl<'a> DataPipelineArtifact<'a> { println!("\n{} {:?}", "Selected context".blue().bold(), context); - let context_index = config::choose_context(self.contexts, context); + let context_index = configuration::choose_context(self.contexts, context); - let fs_config = config::fs_config(self.contexts, collection); + let fs_config = configuration::fs_config(self.contexts, collection); match context_index { 0 => { diff --git a/src/data_pipeline/configuration/mod.rs b/src/data_pipeline/configuration/mod.rs new file mode 100644 index 0000000..f6dc327 --- /dev/null +++ b/src/data_pipeline/configuration/mod.rs @@ -0,0 +1,190 @@ +//! Data pipeline configuration module. + +use colored::Colorize; +use std::{cmp::Ordering, env::args, io}; + +/// The entry point of the program. +pub fn main<'a>( + contexts: [&'a str; 2], + collections: [&'a str; 2], +) -> DataPipelineConfiguration<'a> { + DataPipelineConfiguration::new(contexts, collections) +} + +/// Input arguments of the program. +pub struct InuputArguments { + pub(crate) context: Option, + pub(crate) collection: Option, + pub(crate) search_term: Option, +} + +pub struct DataPipelineConfiguration<'a> { + contexts: [&'a str; 2], + collections: [&'a str; 2], +} + +impl<'a> DataPipelineConfiguration<'a> { + /// Program constructor. + fn new(contexts: [&'a str; 2], collections: [&'a str; 2]) -> DataPipelineConfiguration<'a> { + DataPipelineConfiguration { + contexts, + collections, + } + } + + /// Parses arguments passed to the program. + pub fn args(&mut self) -> InuputArguments { + let arguments: Vec = args().collect(); + + println!("\n{}:\n{:?}", "Arguments".cyan().bold(), arguments); + + let context = arguments.get(2).cloned(); + println!("- context: {:?}", context); + let collection = arguments.get(3).cloned(); + println!("- collection: {:?}", collection); + let search_term = arguments.get(4).cloned(); + println!("- search_term: {:?}", search_term); + + InuputArguments { + context, + collection, + search_term, + } + } + + /// Prompts input from the user, processes it, and returns the index of the selected context. + pub fn choose_context(&self, context_arg: Option) -> usize { + let is_some = context_arg.is_some(); + let mut context_arg_input = if is_some { + match context_arg.unwrap().trim().parse::() { + Ok(value) => value, + Err(_) => String::new(), + } + } else { + String::new() + }; + + loop { + let mut context_input = String::new(); + + if context_arg_input.is_empty() { + self.print_context_instructions(); + + io::stdin() + .read_line(&mut context_input) + .expect("Failed to read line"); + } else { + context_input = context_arg_input.to_string(); + } + + let context_index = match context_input.trim().parse::() { + Ok(num) => num, + Err(_) => continue, + }; + + match context_index.cmp(&self.contexts.len()) { + Ordering::Less => { + return self.select_context(context_index); + } + Ordering::Greater => context_arg_input = self.reset_input_arg(), + Ordering::Equal => context_arg_input = self.reset_input_arg(), + } + } + } + + /// Prints instructions for selecting a context. + fn print_context_instructions(&self) { + println!("\n{}", "Available contexts:".yellow().bold()); + + let max_i = self.contexts.len() - 1; + let mut i = 0; + while i <= max_i { + println!("{}: {}", i, self.contexts[i]); + i += 1; + } + + println!( + "\n{}, [0-{}]:", + "Please select a context".yellow().bold(), + max_i + ); + } + + /// Prints selected context and returns the context index. + fn select_context(&self, context_index: usize) -> usize { + let context = self.contexts[context_index]; + println!("You selected: {}", context); + context_index + } + + /// Prompts input from the user, processes it, and returns the index of the selected context. + pub fn choose_collection(&self, collection_arg: Option) -> usize { + let is_some = collection_arg.is_some(); + let mut collection_arg_input = if is_some { + match collection_arg.unwrap().trim().parse::() { + Ok(value) => value, + Err(_) => String::new(), + } + } else { + String::new() + }; + + loop { + let mut collection_input = String::new(); + + if collection_arg_input.is_empty() { + self.print_collection_instructions(); + + io::stdin() + .read_line(&mut collection_input) + .expect("Failed to read line"); + } else { + collection_input = collection_arg_input.to_string(); + } + + let collection_index = match collection_input.trim().parse::() { + Ok(num) => num, + Err(_) => continue, + }; + + match collection_index.cmp(&self.collections.len()) { + Ordering::Less => { + return self.select_collection(collection_index); + } + Ordering::Greater => collection_arg_input = self.reset_input_arg(), + Ordering::Equal => collection_arg_input = self.reset_input_arg(), + } + } + } + + /// Prints instructions for selecting a collection. + fn print_collection_instructions(&self) { + println!("\n{}", "Available collections:".yellow().bold()); + + let max_i = self.collections.len() - 1; + let mut i = 0; + while i <= max_i { + println!("{}: {}", i, self.collections[i]); + i += 1; + } + + println!( + "\n{}, [0-{}]:", + "Please select a collection".yellow().bold(), + max_i + ); + } + + /// Prints selected collection and returns the collection index. + fn select_collection(&self, collection_index: usize) -> usize { + let collection = self.collections[collection_index]; + println!("You selected: {}", collection); + collection_index + } + + /// Resets the input argument to start over if the option does not exist. + fn reset_input_arg(&self) -> String { + println!("\n{}", "Invalid option.".red()); + String::new() + } +} diff --git a/src/data_pipeline/mod.rs b/src/data_pipeline/mod.rs index afb99a5..77eeba8 100644 --- a/src/data_pipeline/mod.rs +++ b/src/data_pipeline/mod.rs @@ -13,13 +13,13 @@ use octorust::{ types::{Order, RepoSearchResultItem, Repository, WorkflowRun}, }; use std::{ - cmp::Ordering, - env::{self, args}, + env, fs::{self, File}, io, }; mod artifact; +mod configuration; mod environment; mod github; mod mongo; @@ -29,16 +29,10 @@ pub fn main() { DataPipeline::new(); } -/// Input arguments of the program. -struct InuputArguments { - context: Option, - collection: Option, - search_term: Option, -} - struct DataPipeline<'a> { contexts: artifact::Contexts<'a>, collections: mongo::Collections<'a>, + configuration: configuration::DataPipelineConfiguration<'a>, github: github::DataPipelineGitHub, } @@ -47,10 +41,13 @@ impl<'a> DataPipeline<'a> { fn new() -> DataPipeline<'a> { let contexts: artifact::Contexts = artifact::CONTEXTS; let collections: mongo::Collections = mongo::COLLECTIONS; + let configuration: configuration::DataPipelineConfiguration = + configuration::main(contexts, collections); let github: github::DataPipelineGitHub = github::main(); let mut program = DataPipeline { contexts, collections, + configuration, github, }; program.init(); @@ -63,17 +60,17 @@ impl<'a> DataPipeline<'a> { environment::main(None); - let args = self.args(); + let args = self.configuration.args(); let context_arg = args.context.to_owned(); - let context_index = self.choose_context(context_arg); + let context_index = self.configuration.choose_context(context_arg); let context = self.contexts[context_index]; let collection_arg = args.collection.to_owned(); - let collection_index = self.choose_collection(collection_arg); + let collection_index = self.configuration.choose_collection(collection_arg); let collection = self.collections[collection_index]; @@ -98,162 +95,6 @@ impl<'a> DataPipeline<'a> { } } - /// Parses arguments passed to the program. - fn args(&mut self) -> InuputArguments { - let arguments: Vec = args().collect(); - - println!("\n{}:\n{:?}", "Arguments".cyan().bold(), arguments); - - let context = arguments.get(2).cloned(); - println!("- context: {:?}", context); - let collection = arguments.get(3).cloned(); - println!("- collection: {:?}", collection); - let search_term = arguments.get(4).cloned(); - println!("- search_term: {:?}", search_term); - - InuputArguments { - context, - collection, - search_term, - } - } - - /// Prompts input from the user, processes it, and returns the index of the selected context. - fn choose_context(&self, context_arg: Option) -> usize { - let is_some = context_arg.is_some(); - let mut context_arg_input = if is_some { - match context_arg.unwrap().trim().parse::() { - Ok(value) => value, - Err(_) => String::new(), - } - } else { - String::new() - }; - - loop { - let mut context_input = String::new(); - - if context_arg_input.is_empty() { - self.print_context_instructions(); - - io::stdin() - .read_line(&mut context_input) - .expect("Failed to read line"); - } else { - context_input = context_arg_input.to_string(); - } - - let context_index = match context_input.trim().parse::() { - Ok(num) => num, - Err(_) => continue, - }; - - match context_index.cmp(&self.contexts.len()) { - Ordering::Less => { - return self.select_context(context_index); - } - Ordering::Greater => context_arg_input = self.reset_input_arg(), - Ordering::Equal => context_arg_input = self.reset_input_arg(), - } - } - } - - /// Prints instructions for selecting a context. - fn print_context_instructions(&self) { - println!("\n{}", "Available contexts:".yellow().bold()); - - let max_i = self.contexts.len() - 1; - let mut i = 0; - while i <= max_i { - println!("{}: {}", i, self.contexts[i]); - i += 1; - } - - println!( - "\n{}, [0-{}]:", - "Please select a context".yellow().bold(), - max_i - ); - } - - /// Prints selected context and returns the context index. - fn select_context(&self, context_index: usize) -> usize { - let context = self.contexts[context_index]; - println!("You selected: {}", context); - context_index - } - - /// Prompts input from the user, processes it, and returns the index of the selected context. - fn choose_collection(&self, collection_arg: Option) -> usize { - let is_some = collection_arg.is_some(); - let mut collection_arg_input = if is_some { - match collection_arg.unwrap().trim().parse::() { - Ok(value) => value, - Err(_) => String::new(), - } - } else { - String::new() - }; - - loop { - let mut collection_input = String::new(); - - if collection_arg_input.is_empty() { - self.print_collection_instructions(); - - io::stdin() - .read_line(&mut collection_input) - .expect("Failed to read line"); - } else { - collection_input = collection_arg_input.to_string(); - } - - let collection_index = match collection_input.trim().parse::() { - Ok(num) => num, - Err(_) => continue, - }; - - match collection_index.cmp(&self.collections.len()) { - Ordering::Less => { - return self.select_collection(collection_index); - } - Ordering::Greater => collection_arg_input = self.reset_input_arg(), - Ordering::Equal => collection_arg_input = self.reset_input_arg(), - } - } - } - - /// Prints instructions for selecting a collection. - fn print_collection_instructions(&self) { - println!("\n{}", "Available collections:".yellow().bold()); - - let max_i = self.collections.len() - 1; - let mut i = 0; - while i <= max_i { - println!("{}: {}", i, self.collections[i]); - i += 1; - } - - println!( - "\n{}, [0-{}]:", - "Please select a collection".yellow().bold(), - max_i - ); - } - - /// Prints selected collection and returns the collection index. - fn select_collection(&self, collection_index: usize) -> usize { - let collection = self.collections[collection_index]; - println!("You selected: {}", collection); - collection_index - } - - /// Resets the input argument to start over if the option does not exist. - fn reset_input_arg(&self) -> String { - println!("\n{}", "Invalid option.".red()); - String::new() - } - /// The data pipeline program for the provided search_term. fn execute(&mut self, search_term_arg: Option, context: String, collection: String) { let is_some = search_term_arg.is_some(); diff --git a/src/data_pipeline/mongo/repos_collection/mod.rs b/src/data_pipeline/mongo/repos_collection/mod.rs index 0418645..71a5815 100644 --- a/src/data_pipeline/mongo/repos_collection/mod.rs +++ b/src/data_pipeline/mongo/repos_collection/mod.rs @@ -79,9 +79,9 @@ impl MongoDbReposCollection { /// Collects documents for further processing. fn collect_documents(&self, json_data_dir: &str) -> Vec> { - let dir_content_result = fs::read_dir(json_data_dir); + let read_dir_result = fs::read_dir(json_data_dir); - let Ok(dir_content) = dir_content_result else { + let Ok(dir_content) = read_dir_result else { panic!( "\n{} {:?}", "Can't read directory".red().bold(), diff --git a/src/data_pipeline/mongo/workflows_collection/mod.rs b/src/data_pipeline/mongo/workflows_collection/mod.rs index baa0db2..2c355a4 100644 --- a/src/data_pipeline/mongo/workflows_collection/mod.rs +++ b/src/data_pipeline/mongo/workflows_collection/mod.rs @@ -86,9 +86,9 @@ impl MongoDbWorkflowsCollection { /// Collects documents for further processing. fn collect_documents(&self, json_data_dir: &str) -> Vec> { - let dir_content_result = fs::read_dir(json_data_dir); + let read_dir_result = fs::read_dir(json_data_dir); - let Ok(dir_content) = dir_content_result else { + let Ok(dir_content) = read_dir_result else { panic!( "\n{} {:?}", "Can't read directory".red().bold(),