Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 1, 2020
1 parent 67026e4 commit 30925e6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
10 changes: 1 addition & 9 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,12 @@ use git_features::progress;
use gitoxide_core as core;
use std::io::{stderr, stdout};

fn init_log(verbose: bool) {
if verbose {
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
} else {
env_logger::init();
}
}

pub fn main() -> Result<()> {
pub use options::*;
let cli: Args = argh::from_env();
match cli.subcommand {
SubCommands::VerifyPack(VerifyPack { path, verbose }) => {
init_log(verbose);
super::init_env_logger(verbose);
core::verify_pack_or_pack_index(
path,
progress::Log::new("verify-pack").into(),
Expand Down
11 changes: 11 additions & 0 deletions src/plumbing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ pub mod pretty;

#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))]
pub mod lean;

/// If verbose is true, the env logger will be forcibly set to 'info' logging level. Otherwise env logging facilities
/// will just be initialized.
#[cfg(feature = "env_logger")]
fn init_env_logger(verbose: bool) {
if verbose {
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
} else {
env_logger::init();
}
}
6 changes: 1 addition & 5 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ mod options {
}

fn init_progress(name: &str, verbose: bool) -> progress::DoOrDiscard<progress::Log> {
if verbose {
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
} else {
env_logger::init();
}
super::init_env_logger(verbose);
progress::DoOrDiscard::from(if verbose {
Some(progress::Log::new(name))
} else {
Expand Down
2 changes: 1 addition & 1 deletion tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* **progress**
* [x] for `lean` binary behind --verbose flag
* [ ] for `pretty` binary with support for
* [ ] logging
* [x] logging
* [ ] TUI
* [ ] statistics
* [ ] a verbose mode to list each object in a pack, similar to existing git-verify-pack
Expand Down

0 comments on commit 30925e6

Please sign in to comment.