From 34fa6877093f7d8f3ea4e53bd675f99e55a63b6c Mon Sep 17 00:00:00 2001 From: sokorototo Date: Wed, 13 Mar 2024 18:24:21 +0300 Subject: [PATCH] removed complex logging implementation --- .gitignore | 1 + Cargo.lock | 43 +++++--------------------------- vach-cli/Cargo.toml | 8 +++--- vach-cli/src/commands/keypair.rs | 6 ++--- vach-cli/src/commands/pack.rs | 8 +++--- vach-cli/src/commands/split.rs | 6 ++--- vach-cli/src/commands/unpack.rs | 4 +-- vach-cli/src/main.rs | 11 +++----- 8 files changed, 24 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 6b96577d..42aae610 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ perf.data perf.data.old workspace.code-workspace .cargo/config.toml +**.vach diff --git a/Cargo.lock b/Cargo.lock index 32e0bbc1..9da29f99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,9 +75,9 @@ checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" [[package]] name = "atty" @@ -453,19 +453,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" -[[package]] -name = "env_logger" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "errno" version = "0.3.8" @@ -552,12 +539,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "indexmap" version = "1.9.3" @@ -570,9 +551,9 @@ dependencies = [ [[package]] name = "indicatif" -version = "0.17.7" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb28741c9db9a713d93deb3bb9515c20788cef5815265bee4980e87bde7e0f25" +checksum = "763a5a8f45087d6bcea4222e7b72c291a054edf80e4ef6efd2a4979878c7bea3" dependencies = [ "console", "instant", @@ -824,16 +805,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "pretty_env_logger" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" -dependencies = [ - "env_logger", - "log", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1290,8 +1261,6 @@ dependencies = [ "anyhow", "clap 3.2.25", "indicatif", - "log", - "pretty_env_logger", "tabled", "term_size", "vach 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1306,9 +1275,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", diff --git a/vach-cli/Cargo.toml b/vach-cli/Cargo.toml index 4a031738..88d54bbd 100644 --- a/vach-cli/Cargo.toml +++ b/vach-cli/Cargo.toml @@ -21,10 +21,8 @@ path = "src/main.rs" [dependencies] vach = { version = "0.5.5", features = ["all"] } clap = "3.1.15" -indicatif = "0.17.6" -anyhow = "1.0.57" +indicatif = "0.17.8" +anyhow = "1.0.81" tabled = "0.15.0" -log = "0.4.17" -walkdir = "2.3.2" -pretty_env_logger = "0.5.0" +walkdir = "2.5.0" term_size = "0.3.2" diff --git a/vach-cli/src/commands/keypair.rs b/vach-cli/src/commands/keypair.rs index 62de29b4..4c38ab42 100644 --- a/vach-cli/src/commands/keypair.rs +++ b/vach-cli/src/commands/keypair.rs @@ -30,13 +30,13 @@ impl CommandTrait for Evaluator { pk_path.push_str(".pk"); utils::create_and_write_to_file(&sk_path, &kp.to_bytes())?; - log::info!("Secret Key successfully generated and saved in: {}", sk_path); + println!("Secret Key successfully generated and saved in: {}", sk_path); utils::create_and_write_to_file(&pk_path, &kp.verifying_key().to_bytes())?; - log::info!("Public Key successfully generated and saved in: {}", pk_path); + println!("Public Key successfully generated and saved in: {}", pk_path); } else { utils::create_and_write_to_file(&output_path, &kp.to_keypair_bytes())?; - log::info!("KeyPair successfully generated and saved in: {}", output_path); + println!("KeyPair successfully generated and saved in: {}", output_path); } Ok(()) diff --git a/vach-cli/src/commands/pack.rs b/vach-cli/src/commands/pack.rs index 76bb0a2b..e0a5c3d3 100644 --- a/vach-cli/src/commands/pack.rs +++ b/vach-cli/src/commands/pack.rs @@ -92,7 +92,7 @@ impl CommandTrait for Evaluator { match path.canonicalize() { Ok(path) => Some(path), Err(err) => { - log::warn!( + eprintln!( "Failed to evaluate: {}. Skipping due to error: {}", path.to_string_lossy(), err @@ -113,7 +113,7 @@ impl CommandTrait for Evaluator { let path_filter = |path: &PathBuf| match path.canonicalize() { Ok(canonical) => !excludes.contains(&canonical) && canonical.is_file(), Err(err) => { - log::warn!( + eprintln!( "Failed to evaluate: {}. Skipping due to error: {}", path.to_string_lossy(), err @@ -183,7 +183,7 @@ impl CommandTrait for Evaluator { let mut file = File::create("keypair.kp")?; file.write_all(&generated.to_keypair_bytes())?; - log::info!("Generated a new keypair @ keypair.kp"); + println!("Generated a new keypair @ keypair.kp"); kp = Some(generated); } @@ -247,7 +247,7 @@ impl CommandTrait for Evaluator { .trim_start_matches("./") .trim_start_matches(".\\") .to_string(); - log::info!("Preparing {} for packaging", id); + println!("Preparing {} for packaging", id); builder.add(wrapper, &id)?; } diff --git a/vach-cli/src/commands/split.rs b/vach-cli/src/commands/split.rs index 44f9cf5a..6efac485 100644 --- a/vach-cli/src/commands/split.rs +++ b/vach-cli/src/commands/split.rs @@ -35,11 +35,9 @@ impl CommandTrait for Evaluator { utils::create_and_write_to_file(&pk_path, &kp.verifying_key().to_bytes())?; utils::create_and_write_to_file(&sk_path, &kp.to_bytes())?; - log::info!( + println!( "Successfully split keypair: {} -> into {} and {}", - input_path, - pk_path, - sk_path + input_path, pk_path, sk_path ); Ok(()) diff --git a/vach-cli/src/commands/unpack.rs b/vach-cli/src/commands/unpack.rs index e4953840..c0415694 100644 --- a/vach-cli/src/commands/unpack.rs +++ b/vach-cli/src/commands/unpack.rs @@ -84,7 +84,7 @@ impl CommandTrait for Evaluator { // Delete original archive if truncate { - log::info!("Truncating original archive @ {}", &input_path); + println!("Truncating original archive @ {}", &input_path); std::fs::remove_file(input_path)?; }; @@ -141,7 +141,7 @@ fn extract_archive(archive: &Archive, target_fo // Finished extracting pbar.finish(); - log::info!( + println!( "Extracted {} files in {}s", archive.entries().len(), time.elapsed().as_secs_f64() diff --git a/vach-cli/src/main.rs b/vach-cli/src/main.rs index 633faaff..86be4a4a 100644 --- a/vach-cli/src/main.rs +++ b/vach-cli/src/main.rs @@ -6,8 +6,6 @@ mod utils; // NOTE: Unwrapping in a CLI is a no-no. Since throwing Rust developer errors at average users is mental overload fn main() { - pretty_env_logger::init(); - // Build CLI let keys = keys::build_keys(); let app = app::build_app(keys); @@ -16,15 +14,12 @@ fn main() { // Start CLI let matches = app.get_matches(); - let res = match matches.subcommand() { + match matches.subcommand() { Some((key, mtx)) => commands.get(key).unwrap().evaluate(mtx), None => { println!("vach-cli: Run `vach --help` and refer to crates.io/vach-cli for the manual"); Ok(()) }, - }; - - if let Err(err) = res { - log::error!("{}", err) - }; + } + .unwrap(); }