Skip to content

Commit

Permalink
feat(progresss): add flags to disable progress bars
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 12, 2023
1 parent f126d5c commit f988a82
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/lib.rs
Expand Up @@ -162,6 +162,10 @@ pub struct Orogene {
#[arg(global = true, long)]
json: bool,

/// Disable progress bar display.
#[arg(global = true, long)]
no_progress: bool,

#[command(subcommand)]
subcommand: OroCmd,
}
Expand Down Expand Up @@ -193,13 +197,7 @@ impl Orogene {
};

let ilayer = IndicatifLayer::new();
let builder = tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.with_writer(ilayer.get_stderr_writer())
.with_filter(filter),
)
.with(ilayer);
let builder = tracing_subscriber::registry();

if let Some(cache) = self.cache.as_deref() {
let targets = Targets::new()
Expand All @@ -218,13 +216,39 @@ impl Orogene {
tracing_appender::rolling::never(cache.join("_logs"), log_file_name());
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);

builder
.with(fmt::layer().with_writer(non_blocking).with_filter(targets))
.init();
if self.quiet || self.no_progress {
builder
.with(tracing_subscriber::fmt::layer().with_filter(filter))
.with(fmt::layer().with_writer(non_blocking).with_filter(targets))
.init();
} else {
builder
.with(
tracing_subscriber::fmt::layer()
.with_writer(ilayer.get_stderr_writer())
.with_filter(filter),
)
.with(ilayer)
.with(fmt::layer().with_writer(non_blocking).with_filter(targets))
.init();
};

Ok(Some(guard))
} else {
builder.init();
if self.quiet || self.no_progress {
builder
.with(tracing_subscriber::fmt::layer().with_filter(filter))
.init();
} else {
builder
.with(
tracing_subscriber::fmt::layer()
.with_writer(ilayer.get_stderr_writer())
.with_filter(filter),
)
.with(ilayer)
.init();
};
Ok(None)
}
}
Expand Down

0 comments on commit f988a82

Please sign in to comment.