mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Add ls command
This commit is contained in:
parent
267941ae78
commit
ecfbbcf4ac
@ -2,7 +2,7 @@ use anyhow::{bail, Result};
|
||||
use clap::Parser;
|
||||
|
||||
use crate::backend::{FileType, ReadBackend};
|
||||
use crate::index::{indexfiles::AllIndexFiles};
|
||||
use crate::index::indexfiles::AllIndexFiles;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub(super) struct Opts {
|
||||
|
||||
35
src/commands/ls.rs
Normal file
35
src/commands/ls.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use clap::Parser;
|
||||
|
||||
use crate::backend::{FileType, MapResult, ReadBackend};
|
||||
use crate::blob::{Tree, TreeIterator};
|
||||
use crate::id::Id;
|
||||
use crate::index::{indexfiles::AllIndexFiles, ReadIndex};
|
||||
use crate::repo::SnapshotFile;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub(super) struct Opts {
|
||||
/// snapshot to ls
|
||||
id: String,
|
||||
}
|
||||
|
||||
pub(super) fn execute(be: &impl ReadBackend, opts: Opts) -> Result<()> {
|
||||
let id = Id::from_hex(&opts.id).or_else(|_| {
|
||||
// if the given id param is not a full Id, search for a suitable one
|
||||
let res = be.find_starts_with(FileType::Snapshot, &[&opts.id])?[0];
|
||||
match res {
|
||||
MapResult::Some(id) => Ok(id),
|
||||
MapResult::None => Err(anyhow!("no suitable id found for {}", &opts.id)),
|
||||
MapResult::NonUnique => Err(anyhow!("id {} is not unique", &opts.id)),
|
||||
}
|
||||
})?;
|
||||
|
||||
let index = AllIndexFiles::new(be.clone());
|
||||
let snap = SnapshotFile::from_backend(be, id)?;
|
||||
|
||||
for path_node in TreeIterator::from_id(be.clone(), index, snap.tree) {
|
||||
println!("{:?} ", path_node.path);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -6,6 +6,7 @@ use crate::repo;
|
||||
|
||||
mod cat;
|
||||
mod list;
|
||||
mod ls;
|
||||
mod snapshots;
|
||||
|
||||
#[derive(Parser)]
|
||||
@ -33,6 +34,9 @@ enum Command {
|
||||
|
||||
/// cat files
|
||||
Snapshots(snapshots::Opts),
|
||||
|
||||
/// ls snapshots
|
||||
Ls(ls::Opts),
|
||||
}
|
||||
|
||||
pub fn execute() -> Result<()> {
|
||||
@ -43,8 +47,9 @@ pub fn execute() -> Result<()> {
|
||||
let dbe = DecryptBackend::new(&be, key);
|
||||
|
||||
match args.command {
|
||||
Command::List(opts) => list::execute(&be, opts),
|
||||
Command::List(opts) => list::execute(&dbe, opts),
|
||||
Command::Cat(opts) => cat::execute(&be, &dbe, opts),
|
||||
Command::Snapshots(opts) => snapshots::execute(&dbe, opts),
|
||||
Command::Ls(opts) => ls::execute(&dbe, opts),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user