mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Add --no-progress option
This commit is contained in:
parent
3daf283876
commit
e0210b0b03
@ -16,5 +16,7 @@ New features:
|
||||
- Support for extended file attributes has been added.
|
||||
- REST/Rclone backend: Allow to set the request timeout.
|
||||
- Extra or wrong fields in the config file now lead to rustic complaining and aborting.
|
||||
- New option --no-progress has been added.
|
||||
- Option --progress-interval can now also be given as command argument and in the config file.
|
||||
- backup: Paths are now sanitized from command arguments and config file before matching and applying the configuration.
|
||||
- check --read-data: progress bar now also shows total bytes to check and ETA.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Write;
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
@ -11,6 +11,7 @@ use comfy_table::{
|
||||
};
|
||||
use indicatif::HumanDuration;
|
||||
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
|
||||
use lazy_static::lazy_static;
|
||||
use log::*;
|
||||
use rayon::ThreadPoolBuilder;
|
||||
|
||||
@ -22,18 +23,23 @@ pub fn bytes(b: u64) -> String {
|
||||
ByteSize(b).to_string_as(true)
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref PROGRESS_INTERVAL: Mutex<Duration> = Mutex::new(Duration::from_millis(100));
|
||||
pub static ref NO_PROGRESS: Mutex<bool> = Mutex::new(false);
|
||||
}
|
||||
|
||||
fn progress_intervall() -> Duration {
|
||||
let env_name = "RUSTIC_PROGRESS_INTERVAL";
|
||||
std::env::var(env_name)
|
||||
.map(|var| {
|
||||
humantime::Duration::from_str(&var)
|
||||
.expect("{env_name}: please provide a valid duration")
|
||||
.into()
|
||||
})
|
||||
.unwrap_or(Duration::from_millis(100))
|
||||
*PROGRESS_INTERVAL.lock().unwrap()
|
||||
}
|
||||
|
||||
fn is_no_progress() -> bool {
|
||||
*NO_PROGRESS.lock().unwrap()
|
||||
}
|
||||
|
||||
pub fn progress_spinner(prefix: impl Into<Cow<'static, str>>) -> ProgressBar {
|
||||
if is_no_progress() {
|
||||
return no_progress();
|
||||
}
|
||||
let p = ProgressBar::new(0).with_style(
|
||||
ProgressStyle::default_bar()
|
||||
.template("[{elapsed_precise}] {prefix:30} {spinner}")
|
||||
@ -45,6 +51,9 @@ pub fn progress_spinner(prefix: impl Into<Cow<'static, str>>) -> ProgressBar {
|
||||
}
|
||||
|
||||
pub fn progress_counter(prefix: impl Into<Cow<'static, str>>) -> ProgressBar {
|
||||
if is_no_progress() {
|
||||
return no_progress();
|
||||
}
|
||||
let p = ProgressBar::new(0).with_style(
|
||||
ProgressStyle::default_bar()
|
||||
.template("[{elapsed_precise}] {prefix:30} {bar:40.cyan/blue} {pos:>10}/{len:10}")
|
||||
@ -60,6 +69,9 @@ pub fn no_progress() -> ProgressBar {
|
||||
}
|
||||
|
||||
pub fn progress_bytes(prefix: impl Into<Cow<'static, str>>) -> ProgressBar {
|
||||
if is_no_progress() {
|
||||
return no_progress();
|
||||
}
|
||||
let p = ProgressBar::new(0).with_style(
|
||||
ProgressStyle::default_bar()
|
||||
.with_key("my_eta", |s: &ProgressState, w: &mut dyn Write|
|
||||
|
||||
@ -75,6 +75,22 @@ struct GlobalOpts {
|
||||
/// Note: warnings and errors are still additionally printed unless they are ignored by --log-level
|
||||
#[clap(long, global = true, env = "RUSTIC_LOG_FILE", value_name = "LOGFILE")]
|
||||
log_file: Option<PathBuf>,
|
||||
|
||||
/// Don't show any progress bar
|
||||
#[clap(long, global = true, env = "RUSTIC_NO_PROGRESS")]
|
||||
#[merge(strategy=merge::bool::overwrite_false)]
|
||||
no_progress: bool,
|
||||
|
||||
/// Interval to update progress bars
|
||||
#[clap(
|
||||
long,
|
||||
global = true,
|
||||
env = "RUSTIC_PROGRESS_INTERVAL",
|
||||
value_name = "DURATION",
|
||||
conflicts_with = "no-progress"
|
||||
)]
|
||||
#[serde_as(as = "Option<DisplayFromStr>")]
|
||||
progress_interval: Option<humantime::Duration>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@ -183,6 +199,16 @@ pub fn execute() -> Result<()> {
|
||||
])?,
|
||||
}
|
||||
|
||||
if opts.no_progress {
|
||||
let mut no_progress = NO_PROGRESS.lock().unwrap();
|
||||
*no_progress = true;
|
||||
}
|
||||
|
||||
if let Some(duration) = opts.progress_interval {
|
||||
let mut interval = PROGRESS_INTERVAL.lock().unwrap();
|
||||
*interval = *duration;
|
||||
}
|
||||
|
||||
if let Command::SelfUpdate(opts) = args.command {
|
||||
self_update::execute(opts)?;
|
||||
return Ok(());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user