From a46057da1f166eee90411ee27580efd4691e9492 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Wed, 30 Aug 2023 17:29:09 +0200 Subject: [PATCH] cli: Update `rad ls` to look like other commands We render the output of `ls` as a bordered table, like other tabular data in the CLI. --- radicle-cli/examples/rad-init-private.md | 6 ++++- radicle-cli/examples/rad-init.md | 6 ++++- radicle-cli/examples/rad-rm.md | 6 ++++- radicle-cli/src/commands/ls.rs | 29 ++++++++++++++---------- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/radicle-cli/examples/rad-init-private.md b/radicle-cli/examples/rad-init-private.md index d7497a7c..0ae2fa37 100644 --- a/radicle-cli/examples/rad-init-private.md +++ b/radicle-cli/examples/rad-init-private.md @@ -46,5 +46,9 @@ $ rad sync rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu --fetch ✓ Fetching rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu from z6MknSL…StBU8Vi.. ✓ Fetched repository from 1 seed(s) $ rad ls --private -heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu f2de534 radicle heartwood protocol & stack +╭──────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Head Description │ +├──────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu f2de534 radicle heartwood protocol & stack │ +╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/rad-init.md b/radicle-cli/examples/rad-init.md index 37c10752..1b3fc10d 100644 --- a/radicle-cli/examples/rad-init.md +++ b/radicle-cli/examples/rad-init.md @@ -24,5 +24,9 @@ Projects can be listed with the `ls` command: ``` $ rad ls -heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack +╭──────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Head Description │ +├──────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack │ +╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/rad-rm.md b/radicle-cli/examples/rad-rm.md index cb2891e3..fc07bfd5 100644 --- a/radicle-cli/examples/rad-rm.md +++ b/radicle-cli/examples/rad-rm.md @@ -3,7 +3,11 @@ First let's look at what we have locally: ``` $ rad ls -heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack +╭──────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Head Description │ +├──────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack │ +╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ``` Now let's delete the `heartwood` project: diff --git a/radicle-cli/src/commands/ls.rs b/radicle-cli/src/commands/ls.rs index a67006d8..563a8850 100644 --- a/radicle-cli/src/commands/ls.rs +++ b/radicle-cli/src/commands/ls.rs @@ -26,6 +26,7 @@ Options }; pub struct Options { + #[allow(dead_code)] verbose: bool, public: bool, private: bool, @@ -70,26 +71,30 @@ impl Args for Options { pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { let profile = ctx.profile()?; let storage = &profile.storage; - let mut table = term::Table::default(); + let mut table = term::Table::new(term::TableOptions::bordered()); + let repos = storage.repositories()?; - for RepositoryInfo { rid, head, doc } in storage.repositories()? { + if repos.is_empty() { + return Ok(()); + } + table.push([ + "Name".into(), + "RID".into(), + "Head".into(), + "Description".into(), + ]); + table.divider(); + + for RepositoryInfo { rid, head, doc } in repos { if doc.visibility.is_public() && options.private && !options.public { continue; } if !doc.visibility.is_public() && !options.private && options.public { continue; } - - let proj = match doc.verified()?.project() { - Ok(proj) => proj, - Err(err) => { - if options.verbose { - term::warning(&format!("failed to get local project '{rid}': {err}")); - } - continue; - } - }; + let proj = doc.verified()?.project()?; let head = term::format::oid(head).into(); + table.push([ term::format::bold(proj.name().to_owned()), term::format::tertiary(rid.urn()),