summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-08-01 20:21:02 +0300
committerLars Wirzenius <liw@liw.fi>2021-08-01 20:55:03 +0300
commit0835677f33fe8fa89ee96e4c1b45e5711e10b461 (patch)
tree0552880f3cff7141b4410ba1a90b9b7d1a87fe32 /src
parent4c6206a2cb1f8c1efba9fd08a4d6b4fa7d09a6dc (diff)
downloadobnam2-0835677f33fe8fa89ee96e4c1b45e5711e10b461.tar.gz
feat: add command to resolve a generation ref into a chunk id
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/bin/obnam.rs3
-rw-r--r--src/cmd/mod.rs1
-rw-r--r--src/cmd/resolve.rs33
3 files changed, 37 insertions, 0 deletions
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(())
+ }
+}