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:
parent
df5cf4023b
commit
06566dac6f
|
|
@ -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
|
||||
```
|
||||
|
|
|
|||
|
|
@ -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..
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue