From 0835677f33fe8fa89ee96e4c1b45e5711e10b461 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 1 Aug 2021 20:21:02 +0300 Subject: feat: add command to resolve a generation ref into a chunk id Sponsored-by: author --- src/bin/obnam.rs | 3 +++ src/cmd/mod.rs | 1 + src/cmd/resolve.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/cmd/resolve.rs (limited to 'src') diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs index 29de2eb..b2d5683 100644 --- a/src/bin/obnam.rs +++ b/src/bin/obnam.rs @@ -9,6 +9,7 @@ use obnam::cmd::get_chunk::GetChunk; use obnam::cmd::init::Init; use obnam::cmd::list::List; use obnam::cmd::list_files::ListFiles; +use obnam::cmd::resolve::Resolve; use obnam::cmd::restore::Restore; use obnam::cmd::show_config::ShowConfig; use obnam::cmd::show_gen::ShowGeneration; @@ -44,6 +45,7 @@ fn main_program() -> anyhow::Result<()> { Command::List(x) => x.run(&config), Command::ShowGeneration(x) => x.run(&config), Command::ListFiles(x) => x.run(&config), + Command::Resolve(x) => x.run(&config), Command::Restore(x) => x.run(&config), Command::GetChunk(x) => x.run(&config), Command::Config(x) => x.run(&config), @@ -102,6 +104,7 @@ enum Command { ListFiles(ListFiles), Restore(Restore), ShowGeneration(ShowGeneration), + Resolve(Resolve), GetChunk(GetChunk), Config(ShowConfig), EncryptChunk(EncryptChunk), diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 7313a05..502ec5d 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -5,6 +5,7 @@ pub mod get_chunk; pub mod init; pub mod list; pub mod list_files; +pub mod resolve; pub mod restore; pub mod show_config; pub mod show_gen; diff --git a/src/cmd/resolve.rs b/src/cmd/resolve.rs new file mode 100644 index 0000000..a175655 --- /dev/null +++ b/src/cmd/resolve.rs @@ -0,0 +1,33 @@ +use crate::client::AsyncBackupClient; +use crate::config::ClientConfig; +use crate::error::ObnamError; +use structopt::StructOpt; +use tokio::runtime::Runtime; + +#[derive(Debug, StructOpt)] +pub struct Resolve { + generation: String, +} + +impl Resolve { + pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> { + let rt = Runtime::new()?; + rt.block_on(self.run_async(config)) + } + + async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> { + let client = AsyncBackupClient::new(config)?; + let generations = client.list_generations().await?; + + match generations.resolve(&self.generation) { + Err(err) => { + return Err(err.into()); + } + Ok(old_id) => { + println!("{}", old_id); + } + }; + + Ok(()) + } +} -- cgit v1.2.1