diff --git a/radicle-cli/examples/rad-sync.md b/radicle-cli/examples/rad-sync.md new file mode 100644 index 00000000..eaa85eb1 --- /dev/null +++ b/radicle-cli/examples/rad-sync.md @@ -0,0 +1,27 @@ +The `rad sync` command announces changes to the network and waits for other +nodes to be synchronized with those changes. + +For instance let's create an issue and sync it with the network: + +``` +$ rad issue open --title "Test `rad sync`" --description "Check that the command works" -q --no-announce +``` + +Now let's run `rad sync`. This will announce the issue refs to the network and +wait for nodes to announce that they have fetched those refs. + +``` +$ rad sync +✓ Synced with 2 node(s) +``` + +If we try to sync again after the nodes have synced, we will get a timeout +after one second, since the nodes will not emit any message: + +``` +$ rad sync --timeout 1 +✗ Syncing with 2 node(s).. +! Seed z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk timed out.. +! Seed z6Mkux1aUQD2voWWukVb5nNUR7thrHveQG4pDQua8nVhib7Z timed out.. +✗ Sync failed: all seeds timed out +``` diff --git a/radicle-cli/src/commands.rs b/radicle-cli/src/commands.rs index 621ae673..1e86d3c2 100644 --- a/radicle-cli/src/commands.rs +++ b/radicle-cli/src/commands.rs @@ -46,6 +46,8 @@ pub mod rad_review; pub mod rad_rm; #[path = "commands/self.rs"] pub mod rad_self; +#[path = "commands/sync.rs"] +pub mod rad_sync; #[path = "commands/tag.rs"] pub mod rad_tag; #[path = "commands/track.rs"] diff --git a/radicle-cli/src/commands/help.rs b/radicle-cli/src/commands/help.rs index 7d0e5d47..659d484a 100644 --- a/radicle-cli/src/commands/help.rs +++ b/radicle-cli/src/commands/help.rs @@ -40,6 +40,7 @@ const COMMANDS: &[Help] = &[ rad_untag::HELP, rad_untrack::HELP, rad_remote::HELP, + rad_sync::HELP, ]; #[derive(Default)] diff --git a/radicle-cli/src/commands/sync.rs b/radicle-cli/src/commands/sync.rs new file mode 100644 index 00000000..30894c9b --- /dev/null +++ b/radicle-cli/src/commands/sync.rs @@ -0,0 +1,146 @@ +use std::collections::BTreeSet; +use std::ffi::OsString; +use std::path::Path; +use std::{io, time}; + +use anyhow::{anyhow, Context as _}; + +use radicle::node::Event; +use radicle::node::Handle as _; +use radicle::prelude::{Id, NodeId}; + +use crate::terminal as term; +use crate::terminal::args::{Args, Error, Help}; + +pub const HELP: Help = Help { + name: "sync", + description: "Sync repositories to the network", + version: env!("CARGO_PKG_VERSION"), + usage: r#" +Usage + + rad sync [] [