The shared render — the exact local body's table and JSON shapes.
(rows: &[EntryRow], json: bool)
| 80 | |
| 81 | /// The shared render — the exact local body's table and JSON shapes. |
| 82 | pub(crate) fn render_rows(rows: &[EntryRow], json: bool) { |
| 83 | if json { |
| 84 | let json: Vec<serde_json::Value> = rows |
| 85 | .iter() |
| 86 | .map(|e| { |
| 87 | serde_json::json!({ |
| 88 | "path": e.path, |
| 89 | "type": e.entry_type, |
| 90 | "size": e.size, |
| 91 | "updated_at": e.updated_at, |
| 92 | }) |
| 93 | }) |
| 94 | .collect(); |
| 95 | println!("{}", serde_json::to_string_pretty(&json).unwrap()); |
| 96 | return; |
| 97 | } |
| 98 | if rows.is_empty() { |
| 99 | println!("No vault entries found."); |
| 100 | return; |
| 101 | } |
| 102 | for entry in rows { |
| 103 | println!( |
| 104 | " {:12} {:>8} {}", |
| 105 | entry.entry_type, |
| 106 | format_size(entry.size), |
| 107 | entry.path, |
| 108 | ); |
| 109 | } |
| 110 | let count_label = if rows.len() == 1 { "entry" } else { "entries" }; |
| 111 | println!("\n{} {}", rows.len(), count_label); |
| 112 | } |
| 113 | |
| 114 | impl Command for List { |
| 115 | fn run(&self) -> CliResult<()> { |