Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: make the operations more explicit
✗ CI failure Fintan Halpenny committed 6 months ago
commit 502239618e7c62427901147c15134f7fd4e00fd9
parent 894f6a0083f2b198b5cd554041e6734c34e3c207
2 failed (2 total) View logs
2 files changed +43 -14
modified crates/radicle-cli/src/commands/seed.rs
@@ -7,7 +7,6 @@ use radicle::{prelude::*, Node};
use radicle_term::Element as _;

use crate::commands::sync;
-
use crate::node::SyncSettings;
use crate::terminal as term;

pub use args::Args;
@@ -16,16 +15,16 @@ pub(crate) use args::ABOUT;
pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
    let mut node = radicle::Node::new(profile.socket());
-
    let timeout = args.timeout();
-
    let scope = args.scope;
-
    let should_fetch = args.should_fetch();
-

-
    match args.rids {
-
        Some(rids) => {
-
            let settings = SyncSettings::default()
-
                .seeds(args.from)
-
                .timeout(timeout)
-
                .with_profile(&profile);
+

+
    match args::Operation::from(args) {
+
        args::Operation::List => seeding(&profile)?,
+
        args::Operation::Seed {
+
            rids,
+
            should_fetch,
+
            settings,
+
            scope,
+
        } => {
+
            let settings = settings.with_profile(&profile);
            for rid in rids {
                update(rid, scope, &mut node, &profile)?;

@@ -36,7 +35,6 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                }
            }
        }
-
        None => seeding(&profile)?,
    }

    Ok(())
modified crates/radicle-cli/src/commands/seed/args.rs
@@ -2,9 +2,11 @@ use std::time;

use clap::Parser;

+
use nonempty::NonEmpty;
use radicle::node::policy::Scope;
use radicle::prelude::*;

+
use crate::node::SyncSettings;
use crate::terminal;

pub(crate) const ABOUT: &str = "Manage repository seeding policies";
@@ -57,12 +59,41 @@ pub struct Args {
    pub(super) verbose: bool,
}

+
pub(super) enum Operation {
+
    List,
+
    Seed {
+
        rids: NonEmpty<RepoId>,
+
        should_fetch: bool,
+
        settings: SyncSettings,
+
        scope: Scope,
+
    },
+
}
+

+
impl From<Args> for Operation {
+
    fn from(args: Args) -> Self {
+
        let should_fetch = args.should_fetch();
+
        let timeout = args.timeout();
+
        let Args {
+
            rids, from, scope, ..
+
        } = args;
+
        match rids.and_then(NonEmpty::from_vec) {
+
            Some(rids) => Operation::Seed {
+
                rids,
+
                should_fetch,
+
                settings: SyncSettings::default().seeds(from).timeout(timeout),
+
                scope,
+
            },
+
            None => Self::List,
+
        }
+
    }
+
}
+

impl Args {
-
    pub(super) fn timeout(&self) -> time::Duration {
+
    fn timeout(&self) -> time::Duration {
        time::Duration::from_secs(self.timeout)
    }

-
    pub(super) fn should_fetch(&self) -> bool {
+
    fn should_fetch(&self) -> bool {
        match (self.fetch, self.no_fetch) {
            (true, false) => true,
            (false, true) => false,