Skip to content

Commit

Permalink
support for logging in pretty binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 1, 2020
1 parent 7474333 commit 67026e4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ default = ["fast", "pretty-cli"]
fast = ["git-features/parallel", "git-features/fast-sha1"]
pretty-cli = ["structopt",
"git-features/progress-prodash",
"git-features/progress-log",
"prodash/log-renderer",
"prodash/tui-renderer",
"prodash/localtime"]
"prodash/localtime",
"env_logger"]
lean-cli = ["argh", "git-features/progress-log", "env_logger"]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn main() -> Result<()> {
init_log(verbose);
core::verify_pack_or_pack_index(
path,
progress::Log::new("verify").into(),
progress::Log::new("verify-pack").into(),
stdout(),
stderr(),
)
Expand Down
27 changes: 23 additions & 4 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use git_features::progress::Discard;
use git_features::progress;
use gitoxide_core as core;
use std::io::{stderr, stdout};
use structopt::StructOpt;
Expand All @@ -22,20 +22,39 @@ mod options {
/// Verify the integrity of a pack or index file
#[structopt(setting = AppSettings::ColoredHelp)]
VerifyPack {
/// if set, verbose progress messages are printed line by line
#[structopt(long, short = "v")]
verbose: bool,
/// The '.pack' or '.idx' file whose checksum to validate.
#[structopt(parse(from_os_str))]
path: PathBuf,
},
}
}

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();
}
progress::DoOrDiscard::from(if verbose {
Some(progress::Log::new(name))
} else {
None
})
}

pub fn main() -> Result<()> {
use options::*;
let args = Args::from_args();
match args.cmd {
Subcommands::VerifyPack { path } => {
core::verify_pack_or_pack_index(path, Discard.into(), stdout(), stderr())
}
Subcommands::VerifyPack { path, verbose } => core::verify_pack_or_pack_index(
path,
init_progress("verify-pack", verbose).into(),
stdout(),
stderr(),
),
}?;
Ok(())
}
4 changes: 3 additions & 1 deletion tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* [x] validate index and pack
* **progress**
* [x] for `lean` binary behind --verbose flag
* [ ] for `pretty` binary with support for logging and TUI
* [ ] for `pretty` binary with support for
* [ ] logging
* [ ] TUI
* [ ] statistics
* [ ] a verbose mode to list each object in a pack, similar to existing git-verify-pack
* **stress**
Expand Down

0 comments on commit 67026e4

Please sign in to comment.