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:
parent
e59e196da8
commit
a46057da1f
|
|
@ -46,5 +46,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
|
||||||
heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu f2de534 radicle heartwood protocol & stack
|
╭──────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||||
|
│ Name RID Head Description │
|
||||||
|
├──────────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ heartwood rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu f2de534 radicle heartwood protocol & stack │
|
||||||
|
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,9 @@ Projects can be listed with the `ls` command:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rad ls
|
$ rad ls
|
||||||
heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack
|
╭──────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||||
|
│ Name RID Head Description │
|
||||||
|
├──────────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji f2de534 Radicle Heartwood Protocol & Stack │
|
||||||
|
╰──────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,11 @@ First let's look at what we have locally:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rad ls
|
$ 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:
|
Now let's delete the `heartwood` project:
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ Options
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
|
#[allow(dead_code)]
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
public: bool,
|
public: bool,
|
||||||
private: bool,
|
private: bool,
|
||||||
|
|
@ -70,26 +71,30 @@ impl Args for Options {
|
||||||
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let profile = ctx.profile()?;
|
let profile = ctx.profile()?;
|
||||||
let storage = &profile.storage;
|
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 {
|
if doc.visibility.is_public() && options.private && !options.public {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
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 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 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()),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue