Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Fix output of `rad seed` when empty
cloudhead committed 2 years ago
commit 565e3b889cea6bbc16825d801f19a1c87d007ff3
parent f46d396e12e880825cfbd10db471db4f4cae5b34
2 files changed +16 -3
modified radicle-cli/src/commands/seed.rs
@@ -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(())
}
modified radicle-term/src/table.rs
@@ -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);