use dialoguer::{theme::ColorfulTheme, Select};
#[derive(Debug, clap::Args)]
pub(crate) struct RestoreCmd;
impl super::Command for RestoreCmd {
fn run(
&self,
_: &super::nedots::RootCmd,
config: &crate::config::Config,
) -> Result<(), super::CommandError> {
super::backup::backup(
&config.sources,
&config.root.join(super::backup::get_dst()),
true,
)?;
let mut items: Vec<String> = config
.root
.join("backups")
.read_dir()?
.filter(|e| e.is_ok())
.map(|e| e.unwrap().path().to_string_lossy().to_string())
.collect();
items.pop();
items.reverse();
let selection = Select::with_theme(&ColorfulTheme::default())
.items(&items)
.default(0)
.interact_on_opt(&console::Term::stderr())?;
match selection {
Some(index) => println!("User selected item : {}", items[index]),
None => println!("User did not select anything"),
}
Ok(())
}
}