From e85613222f50582ae3a91cef4db9421249096eae Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 21 May 2021 14:32:26 +0100 Subject: [PATCH] otter(1): Do not do progress bars if --quiet Signed-off-by: Ian Jackson --- src/bin/otter.rs | 13 +++++++++++-- src/termprogress.rs | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index e58b7f2b..518fb047 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -113,6 +113,15 @@ impl MainOpts { MgmtGameUpdateMode::Online, ) } + + #[throws(AE)] + fn progressbar(&self) -> Box { + if self.verbose > 0 { + termprogress::new() + } else { + termprogress::NullReporter::new() + } + } } #[derive(Default,Debug)] @@ -829,7 +838,7 @@ mod reset_game { if ma.verbose >= 0 { eprintln!("Re-uploading bundles: {}", why); } - let progress = termprogress::new(); + let progress = ma.progressbar()?; let mut progress = termprogress::Nest::new(local.len(), progress); for bundle in local { bundle.upload(&ma, &mut chan, &mut progress)?; @@ -1633,7 +1642,7 @@ mod upload_bundle { fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) { let args = parse_args::(args, &subargs, &ok_id, None); let mut chan = ma.access_game()?; - let mut progress = termprogress::new(); + let mut progress = ma.progressbar()?; let for_upload = BundleForUpload::prepare(args.bundle_file)?; let bundle = for_upload.upload(&ma, &mut chan, &mut *progress)?; println!("{}", bundle); diff --git a/src/termprogress.rs b/src/termprogress.rs index b7a2d288..0ab271a4 100644 --- a/src/termprogress.rs +++ b/src/termprogress.rs @@ -15,6 +15,9 @@ pub trait Reporter { } pub struct NullReporter; +impl NullReporter { + pub fn new() -> Box { Box::new(NullReporter) } +} #[allow(unused_variables)] impl Reporter for NullReporter { -- 2.30.2