From ba5ed58997a6726cfb8d8c9b260f76c3dd131073 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Fri, 1 Sep 2023 21:51:12 +0200 Subject: [PATCH] cli: Show repo visibility in `rad ls` --- radicle-cli/examples/rad-init-private.md | 10 +++++----- radicle-cli/examples/rad-init.md | 10 +++++----- radicle-cli/examples/rad-rm.md | 10 +++++----- radicle-cli/src/commands/init.rs | 8 ++------ radicle-cli/src/commands/ls.rs | 5 ++++- radicle-cli/src/terminal/format.rs | 14 ++++++++++++++ 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/radicle-cli/examples/rad-init-private.md b/radicle-cli/examples/rad-init-private.md index e41c724b..074d3211 100644 --- a/radicle-cli/examples/rad-init-private.md +++ b/radicle-cli/examples/rad-init-private.md @@ -48,9 +48,9 @@ $ rad sync rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu --fetch ✓ Fetching rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu from z6MknSL…StBU8Vi.. ✓ Fetched repository from 1 seed(s) $ rad ls --private -╭──────────────────────────────────────────────────────────────────────────────────────────────╮ -│ Name RID Head Description │ -├──────────────────────────────────────────────────────────────────────────────────────────────┤ -│ heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu f2de534 radicle heartwood protocol & stack │ -╰──────────────────────────────────────────────────────────────────────────────────────────────╯ +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Visibility Head Description │ +├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu private f2de534 radicle heartwood protocol & stack │ +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/rad-init.md b/radicle-cli/examples/rad-init.md index 5ce1833e..9ba774be 100644 --- a/radicle-cli/examples/rad-init.md +++ b/radicle-cli/examples/rad-init.md @@ -33,9 +33,9 @@ Projects can be listed with the `ls` command: ``` $ rad ls -╭──────────────────────────────────────────────────────────────────────────────────────────────╮ -│ Name RID Head Description │ -├──────────────────────────────────────────────────────────────────────────────────────────────┤ -│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack │ -╰──────────────────────────────────────────────────────────────────────────────────────────────╯ +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Visibility Head Description │ +├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │ +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/radicle-cli/examples/rad-rm.md b/radicle-cli/examples/rad-rm.md index a6e639c1..f4e554b2 100644 --- a/radicle-cli/examples/rad-rm.md +++ b/radicle-cli/examples/rad-rm.md @@ -3,11 +3,11 @@ First let's look at what we have locally: ``` $ rad ls -╭──────────────────────────────────────────────────────────────────────────────────────────────╮ -│ Name RID Head Description │ -├──────────────────────────────────────────────────────────────────────────────────────────────┤ -│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack │ -╰──────────────────────────────────────────────────────────────────────────────────────────────╯ +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Visibility Head Description │ +├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │ +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` Now let's delete the `heartwood` project: diff --git a/radicle-cli/src/commands/init.rs b/radicle-cli/src/commands/init.rs index 04c5fb94..5e2fb62c 100644 --- a/radicle-cli/src/commands/init.rs +++ b/radicle-cli/src/commands/init.rs @@ -203,13 +203,9 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()> term::headline(format!( "Initializing{}radicle 👾 project in {}", if let Some(visibility) = &options.visibility { - if !visibility.is_public() { - term::format::yellow(" private ") - } else { - term::format::positive(" public ") - } + term::format::spaced(term::format::visibility(visibility)) } else { - term::format::default(" ") + term::format::default(" ").into() }, if path == cwd { term::format::tertiary(".").to_string() diff --git a/radicle-cli/src/commands/ls.rs b/radicle-cli/src/commands/ls.rs index 563a8850..bfddbcc1 100644 --- a/radicle-cli/src/commands/ls.rs +++ b/radicle-cli/src/commands/ls.rs @@ -80,6 +80,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { table.push([ "Name".into(), "RID".into(), + "Visibility".into(), "Head".into(), "Description".into(), ]); @@ -92,12 +93,14 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { if !doc.visibility.is_public() && !options.private && options.public { continue; } - let proj = doc.verified()?.project()?; + let doc = doc.verified()?; + let proj = doc.project()?; let head = term::format::oid(head).into(); table.push([ term::format::bold(proj.name().to_owned()), term::format::tertiary(rid.urn()), + term::format::visibility(&doc.visibility).into(), term::format::secondary(head), term::format::italic(proj.description().to_owned()), ]); diff --git a/radicle-cli/src/terminal/format.rs b/radicle-cli/src/terminal/format.rs index f62b8daa..e5a32ead 100644 --- a/radicle-cli/src/terminal/format.rs +++ b/radicle-cli/src/terminal/format.rs @@ -4,6 +4,7 @@ pub use radicle_term::format::*; pub use radicle_term::{style, Paint}; use radicle::cob::{ObjectId, Timestamp}; +use radicle::identity::Visibility; use radicle::node::{Alias, AliasStore, NodeId}; use radicle::prelude::Did; use radicle::profile::Profile; @@ -30,6 +31,11 @@ pub fn parens(input: Paint) -> Paint { Paint::new(format!("({})", input.item)).with_style(input.style) } +/// Wrap spaces around styled input, eg. `"input"` -> `" input "`. +pub fn spaced(input: Paint) -> Paint { + Paint::new(format!(" {} ", input.item)).with_style(input.style) +} + /// Format a command suggestion, eg. `rad init`. pub fn command(cmd: D) -> Paint { primary(format!("`{cmd}`")) @@ -46,6 +52,14 @@ pub fn did(did: &Did) -> Paint { Paint::new(format!("{}…{}", &nid[..7], &nid[nid.len() - 7..])) } +/// Format a Visibility. +pub fn visibility(v: &Visibility) -> Paint<&str> { + match v { + Visibility::Public => term::format::positive("public"), + Visibility::Private { .. } => term::format::secondary("private"), + } +} + /// Remove html style comments from a string. /// /// The html comments must start at the beginning of a line and stop at the end.