cli: Don't override existing seeding scope in `rad seed`
This commit is contained in:
parent
281f92e9ff
commit
52e5581228
|
|
@ -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 │
|
||||||
|
╰───────────────────────────────────────────────────────────╯
|
||||||
|
```
|
||||||
|
|
@ -41,10 +41,19 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
rid: RepoId,
|
rid: RepoId,
|
||||||
scope: Scope,
|
scope: Option<Scope>,
|
||||||
node: &mut Node,
|
node: &mut Node,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> 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 updated = profile.seed(rid, scope, node)?;
|
||||||
let outcome = if updated { "updated" } else { "exists" };
|
let outcome = if updated { "updated" } else { "exists" };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,8 @@ pub struct Args {
|
||||||
timeout: u64,
|
timeout: u64,
|
||||||
|
|
||||||
/// Peer follow scope for this repository
|
/// Peer follow scope for this repository
|
||||||
#[arg(
|
#[arg(long, value_parser = terminal::args::ScopeParser)]
|
||||||
long,
|
pub(super) scope: Option<Scope>,
|
||||||
default_value_t = Scope::Followed,
|
|
||||||
value_parser = terminal::args::ScopeParser
|
|
||||||
)]
|
|
||||||
pub(super) scope: Scope,
|
|
||||||
|
|
||||||
/// Verbose output
|
/// Verbose output
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
|
|
@ -65,7 +61,7 @@ pub(super) enum Operation {
|
||||||
rids: NonEmpty<RepoId>,
|
rids: NonEmpty<RepoId>,
|
||||||
should_fetch: bool,
|
should_fetch: bool,
|
||||||
settings: SyncSettings,
|
settings: SyncSettings,
|
||||||
scope: Scope,
|
scope: Option<Scope>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@ fn rad_seed_and_follow() {
|
||||||
Environment::alice(["rad-seed-and-follow"]);
|
Environment::alice(["rad-seed-and-follow"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rad_seed_scope() {
|
||||||
|
Environment::alice(["rad-seed-scope"]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rad_seed_many() {
|
fn rad_seed_many() {
|
||||||
let mut environment = Environment::new();
|
let mut environment = Environment::new();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue