cli: Announce fork in `rad clone`
This allows peers to know about its existence.
This commit is contained in:
parent
2f1a18470e
commit
8c7c2242cc
|
|
@ -34,6 +34,7 @@ Usage
|
||||||
|
|
||||||
Options
|
Options
|
||||||
|
|
||||||
|
--no-announce Do not announce our new refs to the network
|
||||||
--no-confirm Don't ask for confirmation during clone
|
--no-confirm Don't ask for confirmation during clone
|
||||||
--help Print help
|
--help Print help
|
||||||
|
|
||||||
|
|
@ -45,6 +46,7 @@ pub struct Options {
|
||||||
id: Id,
|
id: Id,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
interactive: Interactive,
|
interactive: Interactive,
|
||||||
|
announce: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args for Options {
|
impl Args for Options {
|
||||||
|
|
@ -54,12 +56,19 @@ impl Args for Options {
|
||||||
let mut parser = lexopt::Parser::from_args(args);
|
let mut parser = lexopt::Parser::from_args(args);
|
||||||
let mut id: Option<Id> = None;
|
let mut id: Option<Id> = None;
|
||||||
let mut interactive = Interactive::Yes;
|
let mut interactive = Interactive::Yes;
|
||||||
|
let mut announce = true;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
Long("no-confirm") => {
|
Long("no-confirm") => {
|
||||||
interactive = Interactive::No;
|
interactive = Interactive::No;
|
||||||
}
|
}
|
||||||
|
Long("no-announce") => {
|
||||||
|
announce = false;
|
||||||
|
}
|
||||||
|
Long("announce") => {
|
||||||
|
announce = true;
|
||||||
|
}
|
||||||
Long("help") => {
|
Long("help") => {
|
||||||
return Err(Error::Help.into());
|
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`")
|
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 profile = ctx.profile()?;
|
||||||
let signer = term::signer(&profile)?;
|
let signer = term::signer(&profile)?;
|
||||||
let mut node = radicle::Node::new(profile.socket());
|
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
|
let delegates = doc
|
||||||
.delegates
|
.delegates
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -140,6 +162,7 @@ pub fn clone<G: Signer>(
|
||||||
signer: &G,
|
signer: &G,
|
||||||
storage: &Storage,
|
storage: &Storage,
|
||||||
node: &mut Node,
|
node: &mut Node,
|
||||||
|
announce: bool,
|
||||||
) -> Result<(raw::Repository, Doc<Verified>, Project), CloneError> {
|
) -> Result<(raw::Repository, Doc<Verified>, Project), CloneError> {
|
||||||
let me = *signer.public_key();
|
let me = *signer.public_key();
|
||||||
|
|
||||||
|
|
@ -178,14 +201,23 @@ pub fn clone<G: Signer>(
|
||||||
|
|
||||||
// Create a local fork of the project, under our own id.
|
// Create a local fork of the project, under our own id.
|
||||||
{
|
{
|
||||||
let spinner = term::spinner(format!(
|
let mut spinner = term::spinner(format!(
|
||||||
"Forking under {}..",
|
"Forking under {}..",
|
||||||
term::format::tertiary(term::format::node(&me))
|
term::format::tertiary(term::format::node(&me))
|
||||||
));
|
));
|
||||||
rad::fork(id, signer, &storage)?;
|
rad::fork(id, signer, &storage)?;
|
||||||
|
|
||||||
|
if announce {
|
||||||
|
if let Err(e) = node.announce_refs(id) {
|
||||||
|
spinner.message("Announcing fork..");
|
||||||
|
spinner.error(e);
|
||||||
|
} else {
|
||||||
spinner.finish();
|
spinner.finish();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
spinner.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let doc = storage.repository(id)?.identity_of(&me)?;
|
let doc = storage.repository(id)?.identity_of(&me)?;
|
||||||
let proj = doc.project()?;
|
let proj = doc.project()?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue