feat: basic list command
parent
0eda768c03
commit
5159bfdddd
|
@ -127,4 +127,8 @@ where
|
||||||
.get(layer)
|
.get(layer)
|
||||||
.map(|manager| manager.restore_backup(start_time))
|
.map(|manager| manager.restore_backup(start_time))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn managers(&self) -> &HashMap<String, Manager<T>> {
|
||||||
|
&self.managers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,4 +181,9 @@ where
|
||||||
|
|
||||||
Err(other("Unknown backup."))
|
Err(other("Unknown backup."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a reference to the underlying chains
|
||||||
|
pub fn chains(&self) -> &Vec<Vec<Backup<T>>> {
|
||||||
|
&self.chains
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::path::PathBuf;
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum BackupCommands {
|
pub enum BackupCommands {
|
||||||
/// List all tracked backups
|
/// List all tracked backups
|
||||||
List,
|
List(BackupListArgs),
|
||||||
/// Manually create a new backup
|
/// Manually create a new backup
|
||||||
Create(BackupCreateArgs),
|
Create(BackupCreateArgs),
|
||||||
/// Restore a backup
|
/// Restore a backup
|
||||||
|
@ -28,6 +28,12 @@ pub struct BackupCreateArgs {
|
||||||
layer: String,
|
layer: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct BackupListArgs {
|
||||||
|
/// What layer to list
|
||||||
|
layer: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
pub struct BackupRestoreArgs {
|
pub struct BackupRestoreArgs {
|
||||||
/// Path to the backup inside the backup directory
|
/// Path to the backup inside the backup directory
|
||||||
|
@ -41,7 +47,7 @@ impl BackupArgs {
|
||||||
pub fn run(&self, cli: &Cli) -> io::Result<()> {
|
pub fn run(&self, cli: &Cli) -> io::Result<()> {
|
||||||
match &self.command {
|
match &self.command {
|
||||||
BackupCommands::Create(args) => args.run(cli),
|
BackupCommands::Create(args) => args.run(cli),
|
||||||
BackupCommands::List => Ok(()),
|
BackupCommands::List(args) => args.run(cli),
|
||||||
BackupCommands::Restore(args) => args.run(cli),
|
BackupCommands::Restore(args) => args.run(cli),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,3 +126,25 @@ impl BackupRestoreArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BackupListArgs {
|
||||||
|
pub fn run(&self, cli: &Cli) -> io::Result<()> {
|
||||||
|
let meta = cli.meta()?;
|
||||||
|
|
||||||
|
for (name, manager) in meta.managers().iter() {
|
||||||
|
println!("{}", name);
|
||||||
|
|
||||||
|
for chain in manager.chains().iter().filter(|c| !c.is_empty()) {
|
||||||
|
let mut iter = chain.iter();
|
||||||
|
let first = iter.next().unwrap();
|
||||||
|
println!(" {}", first.start_time.format(Backup::FILENAME_FORMAT));
|
||||||
|
|
||||||
|
for backup in iter {
|
||||||
|
println!(" {}", backup.start_time.format(Backup::FILENAME_FORMAT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue