mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-04 02:40:32 +08:00
cli: Support --seed on rad clone
Allows specifying one or more seeds to clone from. This is useful for cloning private repositories which are not in the routing table.
This commit is contained in:
@@ -36,10 +36,18 @@ Usage
|
||||
|
||||
rad clone <rid> [<directory>] [--scope <scope>] [<option>...]
|
||||
|
||||
The `clone` command will use your local node's routing table to find seeds from
|
||||
which it can clone the repository.
|
||||
|
||||
For private repositories, the `--seed` option can be passed to clone directly
|
||||
from a known seed in the privacy set.
|
||||
|
||||
Options
|
||||
|
||||
--scope <scope> Follow scope (default: all)
|
||||
--help Print help
|
||||
--scope <scope> Follow scope (default: all)
|
||||
-s, --seed <nid> Clone from this seed (may be specified multiple times)
|
||||
--timeout <secs> Timeout for fetching repository (default: 9)
|
||||
--help Print help
|
||||
|
||||
"#,
|
||||
};
|
||||
@@ -52,6 +60,10 @@ pub struct Options {
|
||||
directory: Option<PathBuf>,
|
||||
/// The seeding scope of the repository.
|
||||
scope: Scope,
|
||||
/// Sync mode.
|
||||
mode: sync::RepoSync,
|
||||
/// Fetch timeout.
|
||||
timeout: time::Duration,
|
||||
}
|
||||
|
||||
impl Args for Options {
|
||||
@@ -61,15 +73,33 @@ impl Args for Options {
|
||||
let mut parser = lexopt::Parser::from_args(args);
|
||||
let mut id: Option<Id> = None;
|
||||
let mut scope = Scope::All;
|
||||
let mut mode = sync::RepoSync::default();
|
||||
let mut timeout = time::Duration::from_secs(9);
|
||||
let mut directory = None;
|
||||
|
||||
while let Some(arg) = parser.next()? {
|
||||
match arg {
|
||||
Long("seed") | Short('s') => {
|
||||
let value = parser.value()?;
|
||||
let value = term::args::nid(&value)?;
|
||||
|
||||
if let sync::RepoSync::Seeds(seeds) = &mut mode {
|
||||
seeds.push(value);
|
||||
} else {
|
||||
mode = sync::RepoSync::Seeds(vec![value]);
|
||||
}
|
||||
}
|
||||
Long("scope") => {
|
||||
let value = parser.value()?;
|
||||
|
||||
scope = term::args::parse_value("scope", value)?;
|
||||
}
|
||||
Long("timeout") => {
|
||||
let value = parser.value()?;
|
||||
let secs = term::args::number(&value)?;
|
||||
|
||||
timeout = time::Duration::from_secs(secs as u64);
|
||||
}
|
||||
Long("no-confirm") => {
|
||||
// We keep this flag here for consistency though it doesn't have any effect,
|
||||
// since the command is fully non-interactive.
|
||||
@@ -99,6 +129,8 @@ impl Args for Options {
|
||||
id,
|
||||
directory,
|
||||
scope,
|
||||
mode,
|
||||
timeout,
|
||||
},
|
||||
vec![],
|
||||
))
|
||||
@@ -120,6 +152,8 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||
options.id,
|
||||
options.directory.clone(),
|
||||
options.scope,
|
||||
options.mode,
|
||||
options.timeout,
|
||||
&mut node,
|
||||
&signer,
|
||||
&profile.storage,
|
||||
@@ -204,6 +238,8 @@ pub fn clone<G: Signer>(
|
||||
id: Id,
|
||||
directory: Option<PathBuf>,
|
||||
scope: Scope,
|
||||
mode: sync::RepoSync,
|
||||
timeout: time::Duration,
|
||||
node: &mut Node,
|
||||
signer: &G,
|
||||
storage: &Storage,
|
||||
@@ -218,7 +254,7 @@ pub fn clone<G: Signer>(
|
||||
> {
|
||||
let me = *signer.public_key();
|
||||
|
||||
// Track.
|
||||
// Seed repository.
|
||||
if node.seed(id, scope)? {
|
||||
term::success!(
|
||||
"Seeding policy updated for {} with scope '{scope}'",
|
||||
@@ -226,12 +262,7 @@ pub fn clone<G: Signer>(
|
||||
);
|
||||
}
|
||||
|
||||
let results = sync::fetch(
|
||||
id,
|
||||
sync::RepoSync::default(),
|
||||
time::Duration::from_secs(9),
|
||||
node,
|
||||
)?;
|
||||
let results = sync::fetch(id, mode, timeout, node)?;
|
||||
let Ok(repository) = storage.repository(id) else {
|
||||
// If we don't have the project locally, even after attempting to fetch,
|
||||
// there's nothing we can do.
|
||||
|
||||
Reference in New Issue
Block a user