Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Add `--scope` flag for `rad clone`
Alexis Sellier committed 2 years ago
commit 06566dac6f5551c62c6509a11aa0da565ef93bd0
parent df5cf4023b3f108ae1ebc842f0784360e69505b5
5 files changed +23 -21
modified radicle-cli/examples/rad-clone-unknown.md
@@ -1,7 +1,7 @@
Trying to clone a repository that is not in our routing table returns an error:

``` (fail)
-
$ rad clone rad:zVNuptPuk5XauitpCWSNVCXGGfXW
-
✓ Tracking relationship established for rad:zVNuptPuk5XauitpCWSNVCXGGfXW
+
$ rad clone rad:zVNuptPuk5XauitpCWSNVCXGGfXW --scope trusted
+
✓ Tracking relationship established for rad:zVNuptPuk5XauitpCWSNVCXGGfXW with scope 'trusted'
✗ Clone failed: no seeds found for rad:zVNuptPuk5XauitpCWSNVCXGGfXW
```
modified radicle-cli/examples/rad-clone.md
@@ -3,7 +3,7 @@ To create a local copy of a repository on the radicle network, we use the

```
$ 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..
✓ Forking under z6Mkt67…v4N1tRk..
✓ Creating checkout in ./heartwood..
modified radicle-cli/src/commands/clone.rs
@@ -22,7 +22,6 @@ use crate::commands::rad_sync as sync;
use crate::project;
use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};
-
use crate::terminal::Interactive;

pub const HELP: Help = Help {
    name: "clone",
@@ -31,13 +30,13 @@ pub const HELP: Help = Help {
    usage: r#"
Usage

-
    rad clone <rid> [<option>...]
+
    rad clone <rid> [--scope <scope>] [<option>...]

Options

-
    --no-announce   Do not announce our new refs to the network
-
    --no-confirm    Don't ask for confirmation during clone
-
    --help          Print help
+
    --scope <scope>   Tracking scope (default: all)
+
    --no-announce     Do not announce our new refs to the network
+
    --help            Print help

"#,
};
@@ -45,9 +44,8 @@ Options
#[derive(Debug)]
pub struct Options {
    id: Id,
-
    #[allow(dead_code)]
-
    interactive: Interactive,
    announce: bool,
+
    scope: Scope,
}

impl Args for Options {
@@ -56,13 +54,19 @@ impl Args for Options {

        let mut parser = lexopt::Parser::from_args(args);
        let mut id: Option<Id> = None;
-
        let mut interactive = Interactive::Yes;
        let mut announce = true;
+
        let mut scope = Scope::All;

        while let Some(arg) = parser.next()? {
            match arg {
+
                Long("scope") => {
+
                    let value = parser.value()?;
+

+
                    scope = term::args::parse_value("scope", value)?;
+
                }
                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") => {
                    announce = false;
@@ -89,7 +93,7 @@ impl Args for Options {
        Ok((
            Options {
                id,
-
                interactive,
+
                scope,
                announce,
            },
            vec![],
@@ -104,6 +108,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    let (working, doc, proj) = clone(
        options.id,
        options.announce,
+
        options.scope,
        &mut node,
        &signer,
        &profile.storage,
@@ -163,6 +168,7 @@ pub enum CloneError {
pub fn clone<G: Signer>(
    id: Id,
    announce: bool,
+
    scope: Scope,
    node: &mut Node,
    signer: &G,
    storage: &Storage,
@@ -170,9 +176,9 @@ pub fn clone<G: Signer>(
    let me = *signer.public_key();

    // Track.
-
    if node.track_repo(id, Scope::default())? {
+
    if node.track_repo(id, scope)? {
        term::success!(
-
            "Tracking relationship established for {}",
+
            "Tracking relationship established for {} with scope '{scope}'",
            term::format::tertiary(id)
        );
    }
modified radicle-cli/src/commands/track.rs
@@ -89,11 +89,7 @@ impl Args for Options {
                (Long("scope"), Some(Operation::TrackRepo { scope, .. })) => {
                    let val = parser.value()?;

-
                    *scope = val
-
                        .to_str()
-
                        .to_owned()
-
                        .ok_or_else(|| anyhow!("scope specified is not UTF-8"))?
-
                        .parse()?;
+
                    *scope = term::args::parse_value("scope", val)?;
                }
                (Long("fetch"), Some(Operation::TrackRepo { .. })) => fetch = true,
                (Long("no-fetch"), Some(Operation::TrackRepo { .. })) => fetch = false,
modified radicle-cli/src/terminal/args.rs
@@ -54,7 +54,7 @@ where
{
    value
        .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()
        .map_err(|e| anyhow!("invalid value specified for '--{}' ({})", flag, e))
}