summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-10 09:35:59 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-10 10:29:27 +0300
commit20a5db2cc1b348087bca5e689ed38f98e1150955 (patch)
tree5c3cef3c30f43045c057c23dd162b5c9c02ceb6d /src/cmd
parent3defb987dad68fa45dbf8a0044adb97104d04a0b (diff)
downloadobnam2-20a5db2cc1b348087bca5e689ed38f98e1150955.tar.gz
refactor: struct GetChunk subcommand
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/get_chunk.rs25
-rw-r--r--src/cmd/mod.rs4
2 files changed, 18 insertions, 11 deletions
diff --git a/src/cmd/get_chunk.rs b/src/cmd/get_chunk.rs
index c9d640e..4ee70fe 100644
--- a/src/cmd/get_chunk.rs
+++ b/src/cmd/get_chunk.rs
@@ -3,14 +3,23 @@ use crate::client::BackupClient;
use crate::config::ClientConfig;
use crate::error::ObnamError;
use std::io::{stdout, Write};
+use structopt::StructOpt;
-pub fn get_chunk(config: &ClientConfig, chunk_id: &str) -> Result<(), ObnamError> {
- let client = BackupClient::new(config)?;
- let chunk_id: ChunkId = chunk_id.parse().unwrap();
- let chunk = client.fetch_chunk(&chunk_id)?;
+#[derive(Debug, StructOpt)]
+pub struct GetChunk {
+ #[structopt()]
+ chunk_id: String,
+}
+
+impl GetChunk {
+ pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> {
+ let client = BackupClient::new(config)?;
+ let chunk_id: ChunkId = self.chunk_id.parse().unwrap();
+ let chunk = client.fetch_chunk(&chunk_id)?;
- let stdout = stdout();
- let mut handle = stdout.lock();
- handle.write_all(chunk.data())?;
- Ok(())
+ let stdout = stdout();
+ let mut handle = stdout.lock();
+ handle.write_all(chunk.data())?;
+ Ok(())
+ }
}
diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs
index 3657d3e..02f4f01 100644
--- a/src/cmd/mod.rs
+++ b/src/cmd/mod.rs
@@ -1,12 +1,10 @@
pub mod backup;
+pub mod get_chunk;
pub mod init;
pub mod list;
pub mod list_files;
pub mod restore;
pub mod show_gen;
-pub mod get_chunk;
-pub use get_chunk::get_chunk;
-
pub mod show_config;
pub use show_config::show_config;