Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli: Don't override existing seeding scope in `rad seed`
Defelo committed 1 month ago
commit 52e5581228f55f344e07ea900313062581fa2324
parent 281f92e
4 files changed +56 -8
added crates/radicle-cli/examples/rad-seed-scope.md
@@ -0,0 +1,38 @@
+
By default `rad seed` should add a seeding policy with the `followed` scope:
+

+
```
+
$ rad seed --no-fetch rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'followed'
+
$ rad seed
+
╭──────────────────────────────────────────────────────────────╮
+
│ Repository                          Name   Policy   Scope    │
+
├──────────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji          allow    followed │
+
╰──────────────────────────────────────────────────────────────╯
+
```
+

+
The policy can be updated by explicitly specifying a different scope:
+

+
```
+
$ rad seed --no-fetch rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --scope all
+
✓ Seeding policy updated for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
+
$ rad seed
+
╭───────────────────────────────────────────────────────────╮
+
│ Repository                          Name   Policy   Scope │
+
├───────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji          allow    all   │
+
╰───────────────────────────────────────────────────────────╯
+
```
+

+
Running `rad seed` again without an explicit scope parameter should not change the existing policy:
+

+
```
+
$ rad seed --no-fetch rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji
+
✓ Seeding policy exists for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji with scope 'all'
+
$ rad seed
+
╭───────────────────────────────────────────────────────────╮
+
│ Repository                          Name   Policy   Scope │
+
├───────────────────────────────────────────────────────────┤
+
│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji          allow    all   │
+
╰───────────────────────────────────────────────────────────╯
+
```
modified crates/radicle-cli/src/commands/seed.rs
@@ -41,10 +41,19 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {

pub fn update(
    rid: RepoId,
-
    scope: Scope,
+
    scope: Option<Scope>,
    node: &mut Node,
    profile: &Profile,
) -> Result<(), anyhow::Error> {
+
    let scope = match scope {
+
        Some(scope) => scope,
+
        None => profile
+
            .policies()?
+
            .seed_policy(&rid)?
+
            .scope()
+
            .unwrap_or(Scope::Followed),
+
    };
+

    let updated = profile.seed(rid, scope, node)?;
    let outcome = if updated { "updated" } else { "exists" };

modified crates/radicle-cli/src/commands/seed/args.rs
@@ -47,12 +47,8 @@ pub struct Args {
    timeout: u64,

    /// Peer follow scope for this repository
-
    #[arg(
-
        long,
-
        default_value_t = Scope::Followed,
-
        value_parser = terminal::args::ScopeParser
-
    )]
-
    pub(super) scope: Scope,
+
    #[arg(long, value_parser = terminal::args::ScopeParser)]
+
    pub(super) scope: Option<Scope>,

    /// Verbose output
    #[arg(long, short)]
@@ -65,7 +61,7 @@ pub(super) enum Operation {
        rids: NonEmpty<RepoId>,
        should_fetch: bool,
        settings: SyncSettings,
-
        scope: Scope,
+
        scope: Option<Scope>,
    },
}

modified crates/radicle-cli/tests/commands/policy.rs
@@ -10,6 +10,11 @@ fn rad_seed_and_follow() {
}

#[test]
+
fn rad_seed_scope() {
+
    Environment::alice(["rad-seed-scope"]);
+
}
+

+
#[test]
fn rad_seed_many() {
    let mut environment = Environment::new();
    let alice = environment.node("alice");