From 8c7c2242cc47cf093078728a6b9f640c88970b96 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Sun, 12 Feb 2023 16:16:30 +0100 Subject: [PATCH] cli: Announce fork in `rad clone` This allows peers to know about its existence. --- radicle-cli/src/commands/clone.rs | 40 +++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/radicle-cli/src/commands/clone.rs b/radicle-cli/src/commands/clone.rs index 81f41b48..ee00fa9c 100644 --- a/radicle-cli/src/commands/clone.rs +++ b/radicle-cli/src/commands/clone.rs @@ -34,6 +34,7 @@ Usage Options + --no-announce Do not announce our new refs to the network --no-confirm Don't ask for confirmation during clone --help Print help @@ -45,6 +46,7 @@ pub struct Options { id: Id, #[allow(dead_code)] interactive: Interactive, + announce: bool, } impl Args for Options { @@ -54,12 +56,19 @@ impl Args for Options { let mut parser = lexopt::Parser::from_args(args); let mut id: Option = None; let mut interactive = Interactive::Yes; + let mut announce = true; while let Some(arg) = parser.next()? { match arg { Long("no-confirm") => { interactive = Interactive::No; } + Long("no-announce") => { + announce = false; + } + Long("announce") => { + announce = true; + } Long("help") => { return Err(Error::Help.into()); } @@ -77,7 +86,14 @@ impl Args for Options { anyhow!("to clone, a radicle id must be provided; see `rad clone --help`") })?; - Ok((Options { id, interactive }, vec![])) + Ok(( + Options { + id, + interactive, + announce, + }, + vec![], + )) } } @@ -85,7 +101,13 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { let profile = ctx.profile()?; let signer = term::signer(&profile)?; let mut node = radicle::Node::new(profile.socket()); - let (working, doc, proj) = clone(options.id, &signer, &profile.storage, &mut node)?; + let (working, doc, proj) = clone( + options.id, + &signer, + &profile.storage, + &mut node, + options.announce, + )?; let delegates = doc .delegates .iter() @@ -140,6 +162,7 @@ pub fn clone( signer: &G, storage: &Storage, node: &mut Node, + announce: bool, ) -> Result<(raw::Repository, Doc, Project), CloneError> { let me = *signer.public_key(); @@ -178,13 +201,22 @@ pub fn clone( // Create a local fork of the project, under our own id. { - let spinner = term::spinner(format!( + let mut spinner = term::spinner(format!( "Forking under {}..", term::format::tertiary(term::format::node(&me)) )); rad::fork(id, signer, &storage)?; - spinner.finish(); + if announce { + if let Err(e) = node.announce_refs(id) { + spinner.message("Announcing fork.."); + spinner.error(e); + } else { + spinner.finish(); + } + } else { + spinner.finish(); + } } let doc = storage.repository(id)?.identity_of(&me)?;