Skip to content

Commit

Permalink
removed complex logging implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sokorototo committed Mar 13, 2024
1 parent ef7582e commit 34fa687
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ perf.data
perf.data.old
workspace.code-workspace
.cargo/config.toml
**.vach
43 changes: 6 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions vach-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions vach-cli/src/commands/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
8 changes: 4 additions & 4 deletions vach-cli/src/commands/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)?;
}

Expand Down
6 changes: 2 additions & 4 deletions vach-cli/src/commands/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions vach-cli/src/commands/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
};

Expand Down Expand Up @@ -141,7 +141,7 @@ fn extract_archive<T: Read + Seek + Send + Sync>(archive: &Archive<T>, target_fo

// Finished extracting
pbar.finish();
log::info!(
println!(
"Extracted {} files in {}s",
archive.entries().len(),
time.elapsed().as_secs_f64()
Expand Down
11 changes: 3 additions & 8 deletions vach-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}

0 comments on commit 34fa687

Please sign in to comment.