cli: Allow multiple RIDs for `rad unseed`

To keep expectations similar to the seed command after the changes in
the companion patch:

rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5/patch/3be0e68b8948e65431a288f225454bafd93de34a
This commit is contained in:
Sekhat Temporus 2025-04-25 23:28:19 +01:00 committed by Lorenz Leutgeb
parent 6bbe919c4b
commit 3018223328
No known key found for this signature in database
3 changed files with 54 additions and 8 deletions

View File

@ -0,0 +1,22 @@
It is possible to use the `rad unseed` command to specify multiple RIDs at the
same time, where each repository specified will stop being seeded.
Let's say we have multiple local repositories we've initialized:
```
$ rad ls
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Name RID Visibility Head Description │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │
│ nixpkgs rad:zyFFr2iwoTEfNF4jGNZHuoy7odMh public f2de534 Home for Nix Packages │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
We could stop seeding them if we didn't want other nodes to fetch them from us:
```
$ rad unseed rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji rad:zyFFr2iwoTEfNF4jGNZHuoy7odMh
✓ Seeding policy for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji removed
✓ Seeding policy for rad:zyFFr2iwoTEfNF4jGNZHuoy7odMh removed
```

View File

@ -1,6 +1,7 @@
use std::ffi::OsString;
use anyhow::anyhow;
use nonempty::NonEmpty;
use radicle::{prelude::*, Node};
@ -14,10 +15,10 @@ pub const HELP: Help = Help {
usage: r#"
Usage
rad unseed <rid> [<option>...]
rad unseed <rid>... [<option>...]
The `unseed` command removes the seeding policy, if found,
for the given repository.
for the given repositories.
Options
@ -27,7 +28,7 @@ Options
#[derive(Debug)]
pub struct Options {
rid: RepoId,
rids: NonEmpty<RepoId>,
}
impl Args for Options {
@ -35,12 +36,13 @@ impl Args for Options {
use lexopt::prelude::*;
let mut parser = lexopt::Parser::from_args(args);
let mut rid: Option<RepoId> = None;
let mut rids: Vec<RepoId> = Vec::new();
while let Some(arg) = parser.next()? {
match &arg {
Value(val) => {
rid = Some(term::args::rid(val)?);
let rid = term::args::rid(val)?;
rids.push(rid);
}
Long("help") | Short('h') => {
return Err(Error::Help.into());
@ -53,8 +55,8 @@ impl Args for Options {
Ok((
Options {
rid: rid.ok_or(anyhow!(
"A Repository ID must be provided; see `rad unseed --help`"
rids: NonEmpty::from_vec(rids).ok_or(anyhow!(
"At least one Repository ID must be provided; see `rad unseed --help`"
))?,
},
vec![],
@ -66,7 +68,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let profile = ctx.profile()?;
let mut node = radicle::Node::new(profile.socket());
delete(options.rid, &mut node, &profile)?;
for rid in options.rids {
delete(rid, &mut node, &profile)?;
}
Ok(())
}

View File

@ -1383,6 +1383,26 @@ fn rad_unseed() {
test("examples/rad-unseed.md", working, Some(&alice.home), []).unwrap();
}
#[test]
fn rad_unseed_many() {
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");
alice.project("nixpkgs", "Home for Nix Packages");
let alice = alice.spawn();
test(
"examples/rad-unseed-many.md",
working,
Some(&alice.home),
[],
)
.unwrap();
}
#[test]
fn rad_block() {
let mut environment = Environment::new();