From 5e3990d411f6ceef2a058ee30b6eaca7df9b445c Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 18 Dec 2023 13:36:05 +0100 Subject: [PATCH] cli: `rad ls` shouldn't show unseeded by default Unseeded repos should not show up in `rad ls`, by default. Only with `--all`. We also use a special visibility of "local" for those projects. --- radicle-cli/examples/rad-unseed.md | 35 ++++++++++++++++++++++++++++++ radicle-cli/src/commands/ls.rs | 12 +++++++++- radicle-cli/tests/commands.rs | 13 +++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 radicle-cli/examples/rad-unseed.md diff --git a/radicle-cli/examples/rad-unseed.md b/radicle-cli/examples/rad-unseed.md new file mode 100644 index 00000000..8d3b00f6 --- /dev/null +++ b/radicle-cli/examples/rad-unseed.md @@ -0,0 +1,35 @@ +Let's say we have a local repository we've initialized: + +``` +$ rad ls +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Visibility Head Description │ +├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │ +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +``` + +We could stop seeding it if didn't want other nodes to fetch it from us: + +``` +$ rad seed --delete rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji +✓ Seeding policy for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji removed +``` + +Now, if we run `rad ls`, we see it's gone: + +``` +$ rad ls +Nothing to show. +``` + +However, with the `--all` flag, we can see it still, but as local-only: + +``` +$ rad ls --all +╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮ +│ Name RID Visibility Head Description │ +├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤ +│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji local f2de534 Radicle Heartwood Protocol & Stack │ +╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ +``` diff --git a/radicle-cli/src/commands/ls.rs b/radicle-cli/src/commands/ls.rs index aa94c712..f8b2d5ea 100644 --- a/radicle-cli/src/commands/ls.rs +++ b/radicle-cli/src/commands/ls.rs @@ -82,6 +82,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { let profile = ctx.profile()?; let storage = &profile.storage; let repos = storage.repositories()?; + let policy = profile.policies()?; let mut table = term::Table::new(term::TableOptions::bordered()); let mut rows = Vec::new(); @@ -105,13 +106,22 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { if refs.is_none() && !options.all { continue; } + let seeded = policy.is_repo_seeded(&rid)?; + + if !seeded && !options.all { + continue; + } let proj = doc.project()?; let head = term::format::oid(head).into(); rows.push([ term::format::bold(proj.name().to_owned()), term::format::tertiary(rid.urn()), - term::format::visibility(&doc.visibility).into(), + if seeded { + term::format::visibility(&doc.visibility).into() + } else { + term::format::tertiary("local").into() + }, term::format::secondary(head), term::format::italic(proj.description().to_owned()), ]); diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index ae1c9b23..f72d9aab 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -728,6 +728,19 @@ fn rad_seed_and_follow() { .unwrap(); } +#[test] +fn rad_unseed() { + let mut environment = Environment::new(); + let mut alice = environment.node(Config::test(Alias::new("alice"))); + let working = tempfile::tempdir().unwrap(); + + // Setup a test project. + alice.project("heartwood", "Radicle Heartwood Protocol & Stack"); + let alice = alice.spawn(); + + test("examples/rad-unseed.md", working, Some(&alice.home), []).unwrap(); +} + #[test] fn rad_clone() { let mut environment = Environment::new();