-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #693 from rustic-rs/noprogress
rustic_core: Add NoProgress and NoProgressBars (e.g. for examples)
- Loading branch information
Showing
13 changed files
with
135 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! `check` example | ||
use rustic_core::{CheckOpts, Repository, RepositoryOptions}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
|
||
fn main() { | ||
// Display info logs | ||
let _ = SimpleLogger::init(LevelFilter::Info, Config::default()); | ||
|
||
// Open repository | ||
let mut repo_opts = RepositoryOptions::default(); | ||
repo_opts.repository = Some("/tmp/repo".to_string()); | ||
repo_opts.password = Some("test".to_string()); | ||
let repo = Repository::new(&repo_opts).unwrap().open().unwrap(); | ||
|
||
// Check respository with standard options | ||
let opts = CheckOpts::default(); | ||
repo.check(opts).unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,69 @@ | ||
use std::borrow::Cow; | ||
|
||
use log::info; | ||
|
||
/// Trait to report progress information for any rustic action which supports that. | ||
/// Implement this trait when you want to display this progress to your users. | ||
pub trait Progress: Send + Sync + Clone { | ||
/// Check if progress is hidden | ||
fn is_hidden(&self) -> bool; | ||
/// Set total length for this progress | ||
fn set_length(&self, len: u64); | ||
/// Set title for this progress | ||
fn set_title(&self, title: &'static str); | ||
/// Advance progress by given increment | ||
fn inc(&self, inc: u64); | ||
/// Finish the progress | ||
fn finish(&self); | ||
} | ||
|
||
/// Trait to start progress information report progress information for any rustic action which supports that. | ||
/// Implement this trait when you want to display this progress to your users. | ||
pub trait ProgressBars { | ||
type P: Progress; | ||
/// Start a new progress, which is hidden | ||
fn progress_hidden(&self) -> Self::P; | ||
/// Start a new progress spinner. Note that this progress doesn't get a length and is not advanced, only finished. | ||
fn progress_spinner(&self, prefix: impl Into<Cow<'static, str>>) -> Self::P; | ||
/// Start a new progress which counts something | ||
fn progress_counter(&self, prefix: impl Into<Cow<'static, str>>) -> Self::P; | ||
fn progress_hidden(&self) -> Self::P; | ||
/// Start a new progress which counts bytes | ||
fn progress_bytes(&self, prefix: impl Into<Cow<'static, str>>) -> Self::P; | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct NoProgress; | ||
impl Progress for NoProgress { | ||
fn is_hidden(&self) -> bool { | ||
true | ||
} | ||
fn set_length(&self, _len: u64) {} | ||
fn set_title(&self, title: &'static str) { | ||
info!("{title}"); | ||
} | ||
fn inc(&self, _inc: u64) {} | ||
fn finish(&self) { | ||
info!("finished."); | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub struct NoProgressBars; | ||
impl ProgressBars for NoProgressBars { | ||
type P = NoProgress; | ||
fn progress_spinner(&self, prefix: impl Into<Cow<'static, str>>) -> Self::P { | ||
info!("{}", prefix.into()); | ||
NoProgress | ||
} | ||
fn progress_counter(&self, prefix: impl Into<Cow<'static, str>>) -> Self::P { | ||
info!("{}", prefix.into()); | ||
NoProgress | ||
} | ||
fn progress_hidden(&self) -> Self::P { | ||
NoProgress | ||
} | ||
fn progress_bytes(&self, prefix: impl Into<Cow<'static, str>>) -> Self::P { | ||
info!("{}", prefix.into()); | ||
NoProgress | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.