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

Implements issue f9ec8a2ee4d52dd7102b001f92f9bea2a96322f9

1 file changed +30 -21 a90aabb1 6bbe919c
modified radicle-cli/src/commands/seed.rs
@@ -22,7 +22,7 @@ pub const HELP: Help = Help {
    usage: r#"
Usage

-
    rad seed [<rid>] [--[no-]fetch] [--from <nid>] [--scope <scope>] [<option>...]
+
    rad seed [<rid> [<rid>...]] [--[no-]fetch] [--from <nid>] [--scope <scope>] [<option>...]

    The `seed` command, when no Repository ID (<rid>) is provided, will list the
    repositories being seeded.
@@ -49,7 +49,7 @@ Options
#[derive(Debug)]
pub enum Operation {
    Seed {
-
        rid: RepoId,
+
        rids: Vec<RepoId>,
        fetch: bool,
        seeds: BTreeSet<NodeId>,
        timeout: time::Duration,
@@ -69,7 +69,7 @@ impl Args for Options {
        use lexopt::prelude::*;

        let mut parser = lexopt::Parser::from_args(args);
-
        let mut rid: Option<RepoId> = None;
+
        let mut rids: Option<Vec<RepoId>> = None;
        let mut scope: Option<Scope> = None;
        let mut fetch: Option<bool> = None;
        let mut timeout = time::Duration::from_secs(9);
@@ -79,7 +79,11 @@ impl Args for Options {
        while let Some(arg) = parser.next()? {
            match &arg {
                Value(val) => {
-
                    rid = Some(term::args::rid(val)?);
+
                    let rid = term::args::rid(val)?;
+
                    let mut vec = rids.unwrap_or_else(|| Vec::new());
+
                    vec.push(rid);
+

+
                    rids = Some(vec);
                }
                Long("scope") => {
                    let val = parser.value()?;
@@ -113,9 +117,9 @@ impl Args for Options {
            }
        }

-
        let op = match rid {
-
            Some(rid) => Operation::Seed {
-
                rid,
+
        let op = match rids {
+
            Some(rids) => Operation::Seed {
+
                rids,
                fetch: fetch.unwrap_or(true),
                scope: scope.unwrap_or(Scope::All),
                timeout,
@@ -134,24 +138,26 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {

    match options.op {
        Operation::Seed {
-
            rid,
+
            rids,
            fetch,
            scope,
            timeout,
            seeds,
        } => {
-
            update(rid, scope, &mut node, &profile)?;
-

-
            if fetch && node.is_running() {
-
                sync::fetch(
-
                    rid,
-
                    SyncSettings::default()
-
                        .seeds(seeds)
-
                        .timeout(timeout)
-
                        .with_profile(&profile),
-
                    &mut node,
-
                    &profile,
-
                )?;
+
            for rid in rids.iter().copied() {
+
                update(rid, scope, &mut node, &profile)?;
+

+
                if fetch && node.is_running() {
+
                    sync::fetch(
+
                        rid,
+
                        SyncSettings::default()
+
                            .seeds(seeds.clone())
+
                            .timeout(timeout)
+
                            .with_profile(&profile),
+
                        &mut node,
+
                        &profile,
+
                    )?;
+
                }
            }
        }
        Operation::List => seeding(&profile)?,
@@ -172,7 +178,10 @@ pub fn update(
    if let Ok(repo) = profile.storage.repository(rid) {
        if repo.identity_doc()?.is_public() {
            profile.add_inventory(rid, node)?;
-
            term::success!("Inventory updated with {}", term::format::tertiary(rid));
+
            term::success!(
+
                "Inventory updated with {}",
+
                term::format::tertiary(rid)
+
            );
        }
    }