Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: timeout helper and clean up borrowing
Fintan Halpenny committed 6 months ago
commit ce5676f2eb88d2d81126a5abd765d4e6341d519d
parent f540f7c6e8f69d8dc36a4013aa19cce00c3e4b32
2 files changed +15 -9
modified crates/radicle-cli/src/commands/seed.rs
@@ -1,7 +1,5 @@
mod args;

-
use std::time;
-

use radicle::node::policy;
use radicle::node::policy::{Policy, Scope};
use radicle::node::Handle;
@@ -18,18 +16,21 @@ 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(ref rids) => {
+
        Some(rids) => {
            for rid in rids {
-
                update(*rid, args.scope, &mut node, &profile)?;
+
                update(rid, scope, &mut node, &profile)?;

-
                if args.should_fetch() && node.is_running() {
+
                if should_fetch && node.is_running() {
                    if let Err(e) = sync::fetch(
-
                        *rid,
+
                        rid,
                        SyncSettings::default()
                            .seeds(args.from.clone())
-
                            .timeout(time::Duration::from_secs(args.timeout))
+
                            .timeout(timeout)
                            .with_profile(&profile),
                        &mut node,
                        &profile,
modified crates/radicle-cli/src/commands/seed/args.rs
@@ -1,3 +1,5 @@
+
use std::time;
+

use clap::Parser;

use radicle::node::policy::Scope;
@@ -40,8 +42,7 @@ pub struct Args {

    /// Fetch timeout in seconds
    #[arg(long, short, value_name = "SECS", default_value_t = 9)]
-
    pub(super) timeout: u64,
-

+
    timeout: u64,
    /// Peer follow scope for this repository
    #[arg(
        long,
@@ -57,6 +58,10 @@ pub struct Args {
}

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

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