mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
feat(commands): ls: Add option --json (#1251)
Co-authored-by: aawsome <37850842+aawsome@users.noreply.github.com>
This commit is contained in:
parent
a21c991b33
commit
63d5f166cd
@ -36,13 +36,17 @@ pub(crate) struct LsCmd {
|
||||
snap: String,
|
||||
|
||||
/// show summary
|
||||
#[clap(long, short = 's')]
|
||||
#[clap(long, short = 's', conflicts_with = "json")]
|
||||
summary: bool,
|
||||
|
||||
/// show long listing
|
||||
#[clap(long, short = 'l')]
|
||||
#[clap(long, short = 'l', conflicts_with = "json")]
|
||||
long: bool,
|
||||
|
||||
/// show listing in json
|
||||
#[clap(long, conflicts_with_all = ["summary", "long"])]
|
||||
json: bool,
|
||||
|
||||
/// show uid/gid instead of user/group
|
||||
#[clap(long, long("numeric-uid-gid"))]
|
||||
numeric_id: bool,
|
||||
@ -135,14 +139,29 @@ impl LsCmd {
|
||||
|
||||
let mut summary = Summary::default();
|
||||
|
||||
if self.json {
|
||||
print!("[");
|
||||
}
|
||||
|
||||
let mut first_item = true;
|
||||
for item in repo.ls(&node, &ls_opts)? {
|
||||
let (path, node) = item?;
|
||||
summary.update(&node);
|
||||
if self.long {
|
||||
if self.json {
|
||||
if !first_item {
|
||||
print!(",");
|
||||
}
|
||||
print!("{}", serde_json::to_string(&path)?);
|
||||
} else if self.long {
|
||||
print_node(&node, &path, self.numeric_id);
|
||||
} else {
|
||||
println!("{}", path.display());
|
||||
}
|
||||
first_item = false;
|
||||
}
|
||||
|
||||
if self.json {
|
||||
println!("]");
|
||||
}
|
||||
|
||||
if self.summary {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user