Binary: Add "verbose" flag
This commit is contained in:
parent
22faadc34e
commit
2b34d9ed01
@ -25,6 +25,24 @@ mod cli;
|
||||
|
||||
static TEMPLATE: &str = "[ {prefix:^30!} ] {wide_bar}{pos:>5.cyan}/{len:5.green}";
|
||||
|
||||
struct Flags {
|
||||
files: bool,
|
||||
color: bool,
|
||||
long: bool,
|
||||
human: bool,
|
||||
}
|
||||
|
||||
impl From<&ArgMatches> for Flags {
|
||||
fn from(value: &ArgMatches) -> Self {
|
||||
Self {
|
||||
files: value.get_flag("files"),
|
||||
color: value.get_flag("color"),
|
||||
long: value.get_flag("long"),
|
||||
human: value.get_flag("human"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let matches = cli::haggis().get_matches();
|
||||
match matches.subcommand() {
|
||||
@ -92,6 +110,7 @@ fn create(matches: &ArgMatches) -> Result<(), haggis::Error> {
|
||||
if let Some(o) = output {
|
||||
pb.println(format!("Creating archive {o}"));
|
||||
}
|
||||
let m = matches.clone();
|
||||
handle = Some(thread::spawn(move || {
|
||||
for msg in &receiver {
|
||||
match msg {
|
||||
@ -103,6 +122,11 @@ fn create(matches: &ArgMatches) -> Result<(), haggis::Error> {
|
||||
pb.set_prefix(format!("{name} added"));
|
||||
}
|
||||
pb.inc(1);
|
||||
if m.get_flag("verbose") {
|
||||
pb.suspend(|| {
|
||||
let _res = print_listing(&n, &m);
|
||||
});
|
||||
}
|
||||
}
|
||||
Message::Eof => {
|
||||
pb.finish_and_clear();
|
||||
@ -186,8 +210,9 @@ fn extract(matches: &ArgMatches) -> Result<(), haggis::Error> {
|
||||
let reader = Decoder::new(fd)?;
|
||||
let mut stream = NodeStream::new(reader)?;
|
||||
let handle = if matches.get_flag("quiet") {
|
||||
let matches = matches.clone();
|
||||
Some(thread::spawn(move || {
|
||||
let t = progress(&file, &receiver, u64::from(stream.length));
|
||||
let t = progress(&file, &receiver, u64::from(stream.length), &matches);
|
||||
total_ref.store(t, Ordering::Relaxed);
|
||||
Ok::<(), haggis::Error>(())
|
||||
}))
|
||||
@ -200,8 +225,9 @@ fn extract(matches: &ArgMatches) -> Result<(), haggis::Error> {
|
||||
let reader = BufReader::new(fd);
|
||||
let mut stream = NodeStream::new(reader)?;
|
||||
let handle = if matches.get_flag("quiet") {
|
||||
let matches = matches.clone();
|
||||
Some(thread::spawn(move || {
|
||||
let t = progress(&file, &receiver, u64::from(stream.length));
|
||||
let t = progress(&file, &receiver, u64::from(stream.length), &matches);
|
||||
total_ref.store(t, Ordering::Relaxed);
|
||||
Ok::<(), haggis::Error>(())
|
||||
}))
|
||||
@ -234,7 +260,7 @@ fn extract(matches: &ArgMatches) -> Result<(), haggis::Error> {
|
||||
}
|
||||
}
|
||||
|
||||
fn progress(file: &str, receiver: &mpsc::Receiver<StreamMessage>, len: u64) -> u64 {
|
||||
fn progress(file: &str, receiver: &mpsc::Receiver<StreamMessage>, len: u64, matches: &ArgMatches) -> u64 {
|
||||
let mut total: u64 = 0;
|
||||
let pb = ProgressBar::new(len);
|
||||
pb.set_style(ProgressStyle::with_template(TEMPLATE).unwrap());
|
||||
@ -250,8 +276,8 @@ fn progress(file: &str, receiver: &mpsc::Receiver<StreamMessage>, len: u64) -> u
|
||||
pb.inc(1);
|
||||
total += size;
|
||||
}
|
||||
ListingKind::SoftLink(t)
|
||||
| ListingKind::HardLink(t) => {
|
||||
ListingKind::SoftLink(ref t)
|
||||
| ListingKind::HardLink(ref t) => {
|
||||
pb.set_prefix(format!("{name} -> {t}"));
|
||||
pb.inc(1);
|
||||
}
|
||||
@ -259,8 +285,8 @@ fn progress(file: &str, receiver: &mpsc::Receiver<StreamMessage>, len: u64) -> u
|
||||
pb.set_prefix(format!("mkdir {name}"));
|
||||
pb.inc(1);
|
||||
}
|
||||
ListingKind::Block(_d)
|
||||
| ListingKind::Character(_d) => {
|
||||
ListingKind::Block(_)
|
||||
| ListingKind::Character(_) => {
|
||||
pb.set_prefix(format!("mknod {name}"));
|
||||
pb.inc(1);
|
||||
}
|
||||
@ -273,6 +299,11 @@ fn progress(file: &str, receiver: &mpsc::Receiver<StreamMessage>, len: u64) -> u
|
||||
break;
|
||||
}
|
||||
}
|
||||
if matches.get_flag("verbose") {
|
||||
pb.suspend(|| {
|
||||
let _res = print_listing(&n, matches);
|
||||
});
|
||||
}
|
||||
}
|
||||
StreamMessage::Eof => {
|
||||
pb.finish_and_clear();
|
||||
|
Loading…
Reference in New Issue
Block a user