diff --git a/.gitignore b/.gitignore index 941c929..ef81082 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /sandbox -/shell.js \ No newline at end of file +/shell.js +/utils.db \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 53168bd..48386c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,21 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.3.2" @@ -131,6 +146,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + [[package]] name = "cc" version = "1.0.83" @@ -146,6 +167,21 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "time", + "wasm-bindgen", + "winapi", +] + [[package]] name = "clap" version = "4.3.23" @@ -368,6 +404,17 @@ dependencies = [ "thread_local", ] +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + [[package]] name = "gimli" version = "0.28.0" @@ -403,6 +450,29 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.3.0" @@ -474,6 +544,15 @@ dependencies = [ "either", ] +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -561,7 +640,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -593,6 +672,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -682,6 +770,12 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f32154ba0af3a075eefa1eda8bb414ee928f62303a54ea85b8d6638ff1a6ee9e" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "predicates" version = "3.0.3" @@ -734,6 +828,36 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3866219251662ec3b26fc217e3e05bf9c4f84325234dfb96bf0bf840889e49" +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.3.5" @@ -855,6 +979,36 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "sqlite" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05439db7afa0ce0b38f6d1b4c691f368adde108df021e15e900fec6a1af92488" +dependencies = [ + "libc", + "sqlite3-sys", +] + +[[package]] +name = "sqlite3-src" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfc95a51a1ee38839599371685b9d4a926abb51791f0bc3bf8c3bb7867e6e454" +dependencies = [ + "cc", + "pkg-config", +] + +[[package]] +name = "sqlite3-sys" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2752c669433e40ebb08fde824146f50d9628aa0b66a3b7fc6be34db82a8063b" +dependencies = [ + "libc", + "sqlite3-src", +] + [[package]] name = "strsim" version = "0.10.0" @@ -901,6 +1055,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -968,6 +1133,7 @@ name = "utils" version = "0.1.0" dependencies = [ "assert_cmd", + "chrono", "clap", "console", "dialoguer", @@ -975,6 +1141,30 @@ dependencies = [ "indicatif", "lettre", "serde", + "sqlite", + "uuid", +] + +[[package]] +name = "uuid" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +dependencies = [ + "getrandom", + "rand", + "uuid-macro-internal", +] + +[[package]] +name = "uuid-macro-internal" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7e1ba1f333bd65ce3c9f27de592fcbc256dafe3af2717f56d7c87761fbaccf4" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -992,12 +1182,72 @@ dependencies = [ "libc", ] +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + [[package]] name = "winapi" version = "0.3.9" @@ -1020,6 +1270,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.45.0" diff --git a/Cargo.toml b/Cargo.toml index 2901df5..d40c83a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,11 +9,13 @@ version = "0.1.0" [dependencies] assert_cmd = "2.0.12" +chrono = "0.4.26" clap = {version = "4.3.23", features = ["derive"]} console = "0.15.7" -dialoguer = { version = "0.10.4", features = ["fuzzy-select", "completion"] } +dialoguer = {version = "0.10.4", features = ["fuzzy-select", "completion"]} include_dir = "0.7.3" indicatif = "0.17.6" lettre = "0.10.4" serde = {versio = "1.0.185", features = ["derive"]} - +sqlite = "0.31.1" +uuid = {version = "1.4.1", features = ["v4", "fast-rng", "macro-diagnostics"]} diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 7390c82..40fe439 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -1,3 +1,10 @@ # Summary -- [Chapter 1](./chapter_1.md) +- [Overview](./overview.md) +- [Store](./store.md) +- [Download](./download.md) +- [Email](./email.md) +- [SMS](./sms.md) +- [Git](./git.md) +- [GitIgnore](./git-ignore.md) +- [Readme](./readme.md) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 783561e..a0fc3ff 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -4,3 +4,4 @@ pub mod email; pub mod gitignore; pub mod readme; pub mod sms; +pub mod store; diff --git a/src/commands/store.rs b/src/commands/store.rs index 1f22ad8..19f642d 100644 --- a/src/commands/store.rs +++ b/src/commands/store.rs @@ -1,3 +1,34 @@ +use clap::{Args, Subcommand}; +use serde::{Deserialize, Serialize}; + // utils store k v -// utils store find -/// all \ No newline at end of file +#[derive(Args, Debug, Serialize)] +pub struct StoreCommands { + /// a unique key + #[clap(short, long, value_parser)] + pub key: String, + ///' value + #[clap(short, long, value_parser)] + pub value: String, + /// sub commands + #[command(subcommand)] + pub subcommands: Option, +} + +#[derive(Debug, Subcommand, Serialize, Deserialize, Clone)] +pub enum StoreSubCommand { + Set, + Add, + Replace, + Remove, +} + +impl StoreCommands { + pub fn parse(&self) { + match &self.subcommands { + Some(StoreSubCommand::Set) => println!("set"), + _ => println!("default"), + } + println!("{:?}", self) + ; } +} diff --git a/src/database.rs b/src/database.rs new file mode 100644 index 0000000..a6c90c9 --- /dev/null +++ b/src/database.rs @@ -0,0 +1,30 @@ +use sqlite::Connection; + +// pub struct Database<'a> { +// path: &'a str, +// } + +pub struct Database; + +impl Database { + pub fn init() -> Connection { + let connection = sqlite::open("./utils.db").unwrap(); + + // create the email table + let email_create_table = + "CREATE TABLE IF NOT EXISTS emails ( id VARCHAR PRIMARY KEY, name VARCHAR, email VARCHAR, message TEXT date TEXT)"; + + let store_create_table = + "CREATE TABLE IF NOT EXISTS store (id VARCHAR, key VARCHAR, value TEXT, date TEXT)"; + + connection.execute(email_create_table).unwrap(); + connection.execute(store_create_table).unwrap(); + + connection + } + + /// return connection to the database; + pub fn conn() -> Connection { + Self::init() + } +} diff --git a/src/main.rs b/src/main.rs index 5210ef6..7e3a589 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,13 @@ +use database::Database; use include_dir::{include_dir, Dir}; use parser::Utils; pub const SOURCE_DIR: Dir = include_dir!("src/templates"); - mod commands; +mod database; mod parser; mod style; mod utils; fn main() { + Database::init(); Utils::run(); } diff --git a/src/parser.rs b/src/parser.rs index 9046eca..026d4dc 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,7 +4,7 @@ use commands::{ readme::ReadmeCommands, sms::SmsCommands, }; -use crate::commands; +use crate::commands::{self, store::StoreCommands}; #[derive(Parser)] #[command(author, version, about, long_about = None)] @@ -39,4 +39,6 @@ pub enum Commands { Sms(SmsCommands), /// include .gitignore GitIgnore(GitIgnoreCommands), + /// store values + Store(StoreCommands), }