summaryrefslogtreecommitdiff
path: root/src/cmd/show_gen.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/show_gen.rs')
-rw-r--r--src/cmd/show_gen.rs51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/cmd/show_gen.rs b/src/cmd/show_gen.rs
index 143aed6..ba39809 100644
--- a/src/cmd/show_gen.rs
+++ b/src/cmd/show_gen.rs
@@ -1,33 +1,42 @@
use crate::client::BackupClient;
-use crate::client::ClientConfig;
+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(())
+ }
}