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.
This commit is contained in:
cloudhead 2023-08-30 17:29:09 +02:00
parent e59e196da8
commit a46057da1f
No known key found for this signature in database
4 changed files with 32 additions and 15 deletions

View File

@ -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 │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
```

View File

@ -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 │
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
```

View File

@ -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:

View File

@ -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()),