From a6bd54c7cbccfebd196a3a501145ea739d9e2c24 Mon Sep 17 00:00:00 2001 From: aawsome <37850842+aawsome@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:44:33 +0200 Subject: [PATCH] more interactive improvements (#1145) restore: - propose path from snapshot as target - handle empty target write snapshots: - clarify that you can enter (y/n) --- src/commands/tui/ls.rs | 16 ++++++++++++++-- src/commands/tui/restore.rs | 9 ++++++--- src/commands/tui/snapshots.rs | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/commands/tui/ls.rs b/src/commands/tui/ls.rs index 40c8a12..0fb6f93 100644 --- a/src/commands/tui/ls.rs +++ b/src/commands/tui/ls.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use anyhow::Result; use crossterm::event::{Event, KeyCode, KeyEventKind}; @@ -199,11 +199,23 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> { Char('n') => self.toggle_numeric(), Char('r') => { if let Some(node) = self.selected_node() { + let is_absolute = self + .snapshot + .paths + .iter() + .any(|p| Path::new(p).is_absolute()); let path = self.path.join(node.name()); + let path = path.display(); + let default_targt = if is_absolute { + format!("/{path}") + } else { + format!("{path}") + }; let restore = Restore::new( self.repo, node.clone(), - format!("{}:{}", self.snapshot.id, path.display()), + format!("{}:/{path}", self.snapshot.id), + &default_targt, ); self.current_screen = CurrentScreen::Restore(restore); } diff --git a/src/commands/tui/restore.rs b/src/commands/tui/restore.rs index 5c18cb3..56e6308 100644 --- a/src/commands/tui/restore.rs +++ b/src/commands/tui/restore.rs @@ -33,10 +33,10 @@ pub(crate) struct Restore<'a, P, S> { } impl<'a, P: ProgressBars, S: IndexedFull> Restore<'a, P, S> { - pub fn new(repo: &'a Repository
, node: Node, source: String) -> Self { + pub fn new(repo: &'a Repository
, node: Node, source: String, path: &str) -> Self {
let opts = RestoreOptions::default();
let title = format!("restore {} to:", source);
- let popup = popup_input(title, "enter restore destination", "", 1);
+ let popup = popup_input(title, "enter restore destination", path, 1);
Self {
current_screen: CurrentScreen::GetDestination(popup),
node,
@@ -47,7 +47,10 @@ impl<'a, P: ProgressBars, S: IndexedFull> Restore<'a, P, S> {
}
}
- pub fn compute_plan(&mut self, dest: String, dry_run: bool) -> Result