cli: add rad fork command
Add a `rad fork` command to create a forked namespace, using the local peer, for the given repository. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
92a14b671f
commit
ea03e8a38b
|
|
@ -14,6 +14,8 @@ pub mod rad_delegate;
|
|||
pub mod rad_edit;
|
||||
#[path = "commands/fetch.rs"]
|
||||
pub mod rad_fetch;
|
||||
#[path = "commands/fork.rs"]
|
||||
pub mod rad_fork;
|
||||
#[path = "commands/help.rs"]
|
||||
pub mod rad_help;
|
||||
#[path = "commands/id.rs"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Context as _;
|
||||
|
||||
use radicle::prelude::Id;
|
||||
use radicle::rad;
|
||||
|
||||
use crate::terminal as term;
|
||||
use crate::terminal::args;
|
||||
use crate::terminal::args::{Args, Error, Help};
|
||||
|
||||
pub const HELP: Help = Help {
|
||||
name: "ls",
|
||||
description: "Create a fork of a project",
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
usage: r#"
|
||||
Usage
|
||||
|
||||
rad fork [<rid>] [<option>...]
|
||||
|
||||
Options
|
||||
|
||||
--help Print help
|
||||
"#,
|
||||
};
|
||||
|
||||
pub struct Options {
|
||||
rid: Option<Id>,
|
||||
}
|
||||
|
||||
impl Args for Options {
|
||||
fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
|
||||
use lexopt::prelude::*;
|
||||
|
||||
let mut parser = lexopt::Parser::from_args(args);
|
||||
let mut rid = None;
|
||||
|
||||
if let Some(arg) = parser.next()? {
|
||||
match arg {
|
||||
Long("help") => {
|
||||
return Err(Error::Help.into());
|
||||
}
|
||||
Value(val) if rid.is_none() => {
|
||||
rid = Some(args::rid(&val)?);
|
||||
}
|
||||
_ => return Err(anyhow::anyhow!(arg.unexpected())),
|
||||
}
|
||||
}
|
||||
|
||||
Ok((Options { rid }, vec![]))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||
let profile = ctx.profile()?;
|
||||
let signer = profile.signer()?;
|
||||
let storage = &profile.storage;
|
||||
|
||||
let rid = match options.rid {
|
||||
Some(rid) => rid,
|
||||
None => {
|
||||
let (_, rid) = radicle::rad::repo(Path::new("."))
|
||||
.context("Current directory is not a radicle project")?;
|
||||
|
||||
rid
|
||||
}
|
||||
};
|
||||
|
||||
rad::fork(rid, &signer, &storage)?;
|
||||
term::success!("Forked project {rid} for {}", profile.id());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ const COMMANDS: &[Help] = &[
|
|||
rad_clone::HELP,
|
||||
rad_edit::HELP,
|
||||
rad_fetch::HELP,
|
||||
rad_fork::HELP,
|
||||
rad_help::HELP,
|
||||
rad_id::HELP,
|
||||
rad_init::HELP,
|
||||
|
|
|
|||
|
|
@ -171,6 +171,14 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
|
|||
args.to_vec(),
|
||||
);
|
||||
}
|
||||
"fork" => {
|
||||
term::run_command_args::<rad_fork::Options, _>(
|
||||
rad_fork::HELP,
|
||||
"Fork",
|
||||
rad_fork::run,
|
||||
args.to_vec(),
|
||||
);
|
||||
}
|
||||
"help" => {
|
||||
term::run_command_args::<rad_help::Options, _>(
|
||||
rad_help::HELP,
|
||||
|
|
|
|||
Loading…
Reference in New Issue