Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Allow specifying multiple rids to the unseed the command
Merged stemporus opened 1 year ago

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

rad patch show 3be0e68b8948e65431a288f225454bafd93de34a
3 files changed +48 -8 6bbe919c 30182233
added radicle-cli/examples/rad-unseed-many.md
@@ -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
+
```
modified radicle-cli/src/commands/unseed.rs
@@ -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(())
}
modified radicle-cli/tests/commands.rs
@@ -1361,6 +1361,20 @@ fn rad_unseed() {
}

#[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();
    let alice = environment.node(Config {