cli: Add `--scope` flag for `rad clone`

This allows for a scope to be specified when cloning.

We also change the default scope when cloning to 'all' to more closely
match user expectations.
This commit is contained in:
Alexis Sellier 2023-06-09 13:29:53 +02:00
parent df5cf4023b
commit 06566dac6f
No known key found for this signature in database
5 changed files with 23 additions and 21 deletions

View File

@ -1,7 +1,7 @@
Trying to clone a repository that is not in our routing table returns an error: Trying to clone a repository that is not in our routing table returns an error:
``` (fail) ``` (fail)
$ rad clone rad:zVNuptPuk5XauitpCWSNVCXGGfXW $ rad clone rad:zVNuptPuk5XauitpCWSNVCXGGfXW --scope trusted
✓ Tracking relationship established for rad:zVNuptPuk5XauitpCWSNVCXGGfXW ✓ Tracking relationship established for rad:zVNuptPuk5XauitpCWSNVCXGGfXW with scope 'trusted'
✗ Clone failed: no seeds found for rad:zVNuptPuk5XauitpCWSNVCXGGfXW ✗ Clone failed: no seeds found for rad:zVNuptPuk5XauitpCWSNVCXGGfXW
``` ```

View File

@ -3,7 +3,7 @@ To create a local copy of a repository on the radicle network, we use the
``` ```
$ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji $ rad clone rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
✓ Tracking relationship established for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji ✓ Tracking relationship established for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6MknSL…StBU8Vi.. ✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6MknSL…StBU8Vi..
✓ Forking under z6Mkt67…v4N1tRk.. ✓ Forking under z6Mkt67…v4N1tRk..
✓ Creating checkout in ./heartwood.. ✓ Creating checkout in ./heartwood..

View File

@ -22,7 +22,6 @@ use crate::commands::rad_sync as sync;
use crate::project; use crate::project;
use crate::terminal as term; use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help}; use crate::terminal::args::{Args, Error, Help};
use crate::terminal::Interactive;
pub const HELP: Help = Help { pub const HELP: Help = Help {
name: "clone", name: "clone",
@ -31,12 +30,12 @@ pub const HELP: Help = Help {
usage: r#" usage: r#"
Usage Usage
rad clone <rid> [<option>...] rad clone <rid> [--scope <scope>] [<option>...]
Options Options
--scope <scope> Tracking scope (default: all)
--no-announce Do not announce our new refs to the network --no-announce Do not announce our new refs to the network
--no-confirm Don't ask for confirmation during clone
--help Print help --help Print help
"#, "#,
@ -45,9 +44,8 @@ Options
#[derive(Debug)] #[derive(Debug)]
pub struct Options { pub struct Options {
id: Id, id: Id,
#[allow(dead_code)]
interactive: Interactive,
announce: bool, announce: bool,
scope: Scope,
} }
impl Args for Options { impl Args for Options {
@ -56,13 +54,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 announce = true; let mut announce = true;
let mut scope = Scope::All;
while let Some(arg) = parser.next()? { while let Some(arg) = parser.next()? {
match arg { match arg {
Long("scope") => {
let value = parser.value()?;
scope = term::args::parse_value("scope", value)?;
}
Long("no-confirm") => { Long("no-confirm") => {
interactive = Interactive::No; // We keep this flag here for consistency though it doesn't have any effect,
// since the command is fully non-interactive.
} }
Long("no-announce") => { Long("no-announce") => {
announce = false; announce = false;
@ -89,7 +93,7 @@ impl Args for Options {
Ok(( Ok((
Options { Options {
id, id,
interactive, scope,
announce, announce,
}, },
vec![], vec![],
@ -104,6 +108,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let (working, doc, proj) = clone( let (working, doc, proj) = clone(
options.id, options.id,
options.announce, options.announce,
options.scope,
&mut node, &mut node,
&signer, &signer,
&profile.storage, &profile.storage,
@ -163,6 +168,7 @@ pub enum CloneError {
pub fn clone<G: Signer>( pub fn clone<G: Signer>(
id: Id, id: Id,
announce: bool, announce: bool,
scope: Scope,
node: &mut Node, node: &mut Node,
signer: &G, signer: &G,
storage: &Storage, storage: &Storage,
@ -170,9 +176,9 @@ pub fn clone<G: Signer>(
let me = *signer.public_key(); let me = *signer.public_key();
// Track. // Track.
if node.track_repo(id, Scope::default())? { if node.track_repo(id, scope)? {
term::success!( term::success!(
"Tracking relationship established for {}", "Tracking relationship established for {} with scope '{scope}'",
term::format::tertiary(id) term::format::tertiary(id)
); );
} }

View File

@ -89,11 +89,7 @@ impl Args for Options {
(Long("scope"), Some(Operation::TrackRepo { scope, .. })) => { (Long("scope"), Some(Operation::TrackRepo { scope, .. })) => {
let val = parser.value()?; let val = parser.value()?;
*scope = val *scope = term::args::parse_value("scope", val)?;
.to_str()
.to_owned()
.ok_or_else(|| anyhow!("scope specified is not UTF-8"))?
.parse()?;
} }
(Long("fetch"), Some(Operation::TrackRepo { .. })) => fetch = true, (Long("fetch"), Some(Operation::TrackRepo { .. })) => fetch = true,
(Long("no-fetch"), Some(Operation::TrackRepo { .. })) => fetch = false, (Long("no-fetch"), Some(Operation::TrackRepo { .. })) => fetch = false,

View File

@ -54,7 +54,7 @@ where
{ {
value value
.into_string() .into_string()
.map_err(|_| anyhow!("the value specified for '--{}' is not valid unicode", flag))? .map_err(|_| anyhow!("the value specified for '--{}' is not valid UTF-8", flag))?
.parse() .parse()
.map_err(|e| anyhow!("invalid value specified for '--{}' ({})", flag, e)) .map_err(|e| anyhow!("invalid value specified for '--{}' ({})", flag, e))
} }