diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-10 09:22:45 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-10 10:29:27 +0300 |
commit | 7a32584448ebe00bdb45aa5daf506ce37c4811e0 (patch) | |
tree | 33249e98feb9f38b66d8961df007589798d875e4 /src/cmd/show_gen.rs | |
parent | c196a68471dd9dafbcc4030342aa4164d7a2d3e3 (diff) | |
download | obnam2-7a32584448ebe00bdb45aa5daf506ce37c4811e0.tar.gz |
refactor: struct ShowGeneration subcommand
Diffstat (limited to 'src/cmd/show_gen.rs')
-rw-r--r-- | src/cmd/show_gen.rs | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/src/cmd/show_gen.rs b/src/cmd/show_gen.rs index 5b786cf..ba39809 100644 --- a/src/cmd/show_gen.rs +++ b/src/cmd/show_gen.rs @@ -3,31 +3,40 @@ use crate::config::ClientConfig; use crate::error::ObnamError; use crate::fsentry::FilesystemKind; use indicatif::HumanBytes; +use structopt::StructOpt; use tempfile::NamedTempFile; -pub fn show_generation(config: &ClientConfig, gen_ref: &str) -> Result<(), ObnamError> { - let temp = NamedTempFile::new()?; +#[derive(Debug, StructOpt)] +pub struct ShowGeneration { + #[structopt(default_value = "latest")] + gen_id: String, +} + +impl ShowGeneration { + pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> { + let temp = NamedTempFile::new()?; - let client = BackupClient::new(config)?; + let client = BackupClient::new(config)?; - let genlist = client.list_generations()?; - let gen_id: String = genlist.resolve(gen_ref)?; - let gen = client.fetch_generation(&gen_id, temp.path())?; - let files = gen.files()?; + let genlist = client.list_generations()?; + let gen_id: String = genlist.resolve(&self.gen_id)?; + let gen = client.fetch_generation(&gen_id, temp.path())?; + let files = gen.files()?; - let total_bytes = files.iter().fold(0, |acc, file| { - let e = file.entry(); - if e.kind() == FilesystemKind::Regular { - acc + file.entry().len() - } else { - acc - } - }); + let total_bytes = files.iter().fold(0, |acc, file| { + let e = file.entry(); + if e.kind() == FilesystemKind::Regular { + acc + file.entry().len() + } else { + acc + } + }); - println!("generation-id: {}", gen_id); - println!("file-count: {}", gen.file_count()?); - println!("file-bytes: {}", HumanBytes(total_bytes)); - println!("file-bytes-raw: {}", total_bytes); + println!("generation-id: {}", gen_id); + println!("file-count: {}", gen.file_count()?); + println!("file-bytes: {}", HumanBytes(total_bytes)); + println!("file-bytes-raw: {}", total_bytes); - Ok(()) + Ok(()) + } } |