cli: Fix output of `rad seed` when empty

This commit is contained in:
cloudhead 2024-02-07 15:45:50 +01:00
parent f46d396e12
commit 565e3b889c
No known key found for this signature in database
2 changed files with 16 additions and 3 deletions

View File

@ -176,7 +176,7 @@ pub fn delete(rid: RepoId, node: &mut Node, profile: &Profile) -> anyhow::Result
pub fn seeding(profile: &Profile) -> anyhow::Result<()> {
let store = profile.policies()?;
let mut t = term::Table::new(term::table::TableOptions::bordered());
t.push([
t.header([
term::format::default(String::from("RID")),
term::format::default(String::from("Scope")),
term::format::default(String::from("Policy")),
@ -199,7 +199,12 @@ pub fn seeding(profile: &Profile) -> anyhow::Result<()> {
term::format::secondary(policy),
])
}
t.print();
if t.is_empty() {
term::print(term::format::dim("No seeding policies to show."));
} else {
t.print();
}
Ok(())
}

View File

@ -56,6 +56,7 @@ impl TableOptions {
#[derive(Debug)]
enum Row<const W: usize, T> {
Header([T; W]),
Data([T; W]),
Divider,
}
@ -104,7 +105,7 @@ where
let mut line = Line::default();
match row {
Row::Data(cells) => {
Row::Header(cells) | Row::Data(cells) => {
if let Some(color) = border {
line.push(Paint::new("").fg(color));
}
@ -178,6 +179,13 @@ impl<const W: usize, T: Cell> Table<W, T> {
self.rows.push(Row::Data(row));
}
pub fn header(&mut self, row: [T; W]) {
for (i, cell) in row.iter().enumerate() {
self.widths[i] = self.widths[i].max(cell.width());
}
self.rows.push(Row::Header(row));
}
pub fn extend(&mut self, rows: impl IntoIterator<Item = [T; W]>) {
for row in rows.into_iter() {
self.push(row);