diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-10 09:35:59 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-10 10:29:27 +0300 |
commit | 20a5db2cc1b348087bca5e689ed38f98e1150955 (patch) | |
tree | 5c3cef3c30f43045c057c23dd162b5c9c02ceb6d /src/cmd/get_chunk.rs | |
parent | 3defb987dad68fa45dbf8a0044adb97104d04a0b (diff) | |
download | obnam2-20a5db2cc1b348087bca5e689ed38f98e1150955.tar.gz |
refactor: struct GetChunk subcommand
Diffstat (limited to 'src/cmd/get_chunk.rs')
-rw-r--r-- | src/cmd/get_chunk.rs | 25 |
1 files changed, 17 insertions, 8 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(()) + } } |