cli: Show repo visibility in `rad ls`

This commit is contained in:
cloudhead 2023-09-01 21:51:12 +02:00
parent befc76e030
commit ba5ed58997
No known key found for this signature in database
6 changed files with 35 additions and 22 deletions

View File

@ -48,9 +48,9 @@ $ rad sync rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu --fetch
✓ Fetching rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu from z6MknSL…StBU8Vi.. ✓ Fetching rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu from z6MknSL…StBU8Vi..
✓ Fetched repository from 1 seed(s) ✓ Fetched repository from 1 seed(s)
$ rad ls --private $ rad ls --private
╭──────────────────────────────────────────────────────────────────────────────────────────────╮ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────
│ Name RID Head Description │ │ Name RID Visibility Head Description │
├──────────────────────────────────────────────────────────────────────────────────────────────┤ ├───────────────────────────────────────────────────────────────────────────────────────────────────────────
│ heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu f2de534 radicle heartwood protocol & stack │ │ heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu private f2de534 radicle heartwood protocol & stack │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────
``` ```

View File

@ -33,9 +33,9 @@ Projects can be listed with the `ls` command:
``` ```
$ rad ls $ rad ls
╭──────────────────────────────────────────────────────────────────────────────────────────────╮ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────
│ Name RID Head Description │ │ Name RID Visibility Head Description │
├──────────────────────────────────────────────────────────────────────────────────────────────┤ ├───────────────────────────────────────────────────────────────────────────────────────────────────────────
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack │ │ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────
``` ```

View File

@ -3,11 +3,11 @@ First let's look at what we have locally:
``` ```
$ rad ls $ rad ls
╭──────────────────────────────────────────────────────────────────────────────────────────────╮ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────
│ Name RID Head Description │ │ Name RID Visibility Head Description │
├──────────────────────────────────────────────────────────────────────────────────────────────┤ ├───────────────────────────────────────────────────────────────────────────────────────────────────────────
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack │ │ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────
``` ```
Now let's delete the `heartwood` project: Now let's delete the `heartwood` project:

View File

@ -203,13 +203,9 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
term::headline(format!( term::headline(format!(
"Initializing{}radicle 👾 project in {}", "Initializing{}radicle 👾 project in {}",
if let Some(visibility) = &options.visibility { if let Some(visibility) = &options.visibility {
if !visibility.is_public() { term::format::spaced(term::format::visibility(visibility))
term::format::yellow(" private ")
} else {
term::format::positive(" public ")
}
} else { } else {
term::format::default(" ") term::format::default(" ").into()
}, },
if path == cwd { if path == cwd {
term::format::tertiary(".").to_string() term::format::tertiary(".").to_string()

View File

@ -80,6 +80,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
table.push([ table.push([
"Name".into(), "Name".into(),
"RID".into(), "RID".into(),
"Visibility".into(),
"Head".into(), "Head".into(),
"Description".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 { if !doc.visibility.is_public() && !options.private && options.public {
continue; continue;
} }
let proj = doc.verified()?.project()?; let doc = doc.verified()?;
let proj = doc.project()?;
let head = term::format::oid(head).into(); let head = term::format::oid(head).into();
table.push([ table.push([
term::format::bold(proj.name().to_owned()), term::format::bold(proj.name().to_owned()),
term::format::tertiary(rid.urn()), term::format::tertiary(rid.urn()),
term::format::visibility(&doc.visibility).into(),
term::format::secondary(head), term::format::secondary(head),
term::format::italic(proj.description().to_owned()), term::format::italic(proj.description().to_owned()),
]); ]);

View File

@ -4,6 +4,7 @@ pub use radicle_term::format::*;
pub use radicle_term::{style, Paint}; pub use radicle_term::{style, Paint};
use radicle::cob::{ObjectId, Timestamp}; use radicle::cob::{ObjectId, Timestamp};
use radicle::identity::Visibility;
use radicle::node::{Alias, AliasStore, NodeId}; use radicle::node::{Alias, AliasStore, NodeId};
use radicle::prelude::Did; use radicle::prelude::Did;
use radicle::profile::Profile; use radicle::profile::Profile;
@ -30,6 +31,11 @@ pub fn parens<D: fmt::Display>(input: Paint<D>) -> Paint<String> {
Paint::new(format!("({})", input.item)).with_style(input.style) Paint::new(format!("({})", input.item)).with_style(input.style)
} }
/// Wrap spaces around styled input, eg. `"input"` -> `" input "`.
pub fn spaced<D: fmt::Display>(input: Paint<D>) -> Paint<String> {
Paint::new(format!(" {} ", input.item)).with_style(input.style)
}
/// Format a command suggestion, eg. `rad init`. /// Format a command suggestion, eg. `rad init`.
pub fn command<D: fmt::Display>(cmd: D) -> Paint<String> { pub fn command<D: fmt::Display>(cmd: D) -> Paint<String> {
primary(format!("`{cmd}`")) primary(format!("`{cmd}`"))
@ -46,6 +52,14 @@ pub fn did(did: &Did) -> Paint<String> {
Paint::new(format!("{}{}", &nid[..7], &nid[nid.len() - 7..])) 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. /// Remove html style comments from a string.
/// ///
/// The html comments must start at the beginning of a line and stop at the end. /// The html comments must start at the beginning of a line and stop at the end.