From e5fcbba4c04369e1124859ed845f711489910342 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Wed, 7 Feb 2024 15:47:51 +0100 Subject: [PATCH] cli: Implement `rad block` command Blocks repos & nodes from beeing seeded/followed. --- radicle-cli/examples/rad-block.md | 43 ++++++++++++++ radicle-cli/src/commands.rs | 2 + radicle-cli/src/commands/block.rs | 96 +++++++++++++++++++++++++++++++ radicle-cli/src/commands/help.rs | 1 + radicle-cli/src/main.rs | 7 +++ radicle-cli/tests/commands.rs | 12 ++++ 6 files changed, 161 insertions(+) create mode 100644 radicle-cli/examples/rad-block.md create mode 100644 radicle-cli/src/commands/block.rs diff --git a/radicle-cli/examples/rad-block.md b/radicle-cli/examples/rad-block.md new file mode 100644 index 00000000..164f72a4 --- /dev/null +++ b/radicle-cli/examples/rad-block.md @@ -0,0 +1,43 @@ +When using an open seeding policy, it can be useful to block individual +repositories from being seeded. + +For instance, if our default policy is to seed, any unknown repository will +have its policy set to allow seeding: +``` +$ rad inspect rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --policy +Repository rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji is being seeded with scope `followed` +``` + +Since there is no policy specific to this repository, there's nothing to be +removed. + +``` +$ rad seed +No seeding policies to show. +``` + +But if we wanted to prevent this repository from being seeded, while +allowing all other repositories, we could use `rad block`: + +``` +$ rad block rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji +✓ Policy for rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji set to 'block' +``` + +We can see that it is now no longer seeded: + +``` +$ rad inspect rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --policy +Repository rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji is not being seeded +``` + +And a 'block' policy was added: + +``` +$ rad seed +╭───────────────────────────────────────────────────────╮ +│ RID Scope Policy │ +├───────────────────────────────────────────────────────┤ +│ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji followed block │ +╰───────────────────────────────────────────────────────╯ +``` diff --git a/radicle-cli/src/commands.rs b/radicle-cli/src/commands.rs index 3ea9f0b3..515a3ab4 100644 --- a/radicle-cli/src/commands.rs +++ b/radicle-cli/src/commands.rs @@ -1,5 +1,7 @@ #[path = "commands/auth.rs"] pub mod rad_auth; +#[path = "commands/block.rs"] +pub mod rad_block; #[path = "commands/checkout.rs"] pub mod rad_checkout; #[path = "commands/clean.rs"] diff --git a/radicle-cli/src/commands/block.rs b/radicle-cli/src/commands/block.rs new file mode 100644 index 00000000..09050483 --- /dev/null +++ b/radicle-cli/src/commands/block.rs @@ -0,0 +1,96 @@ +use std::ffi::OsString; + +use radicle::node::policy::Policy; +use radicle::prelude::{NodeId, RepoId}; + +use crate::terminal as term; +use crate::terminal::args; +use crate::terminal::args::{Args, Error, Help}; + +pub const HELP: Help = Help { + name: "block", + description: "Block repositories or nodes from being seeded or followed", + version: env!("CARGO_PKG_VERSION"), + usage: r#" +Usage + + rad block [