Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli/unblock: Use clap
✗ CI failure Erik Kundt committed 6 months ago
commit 74ae301309b10608ba605c145c53c7f1bc4b087a
parent df7518c3fa5db714f60ba2b1f08d7a665c2b1e58
2 failed (2 total) View logs
4 files changed +33 -89
modified crates/radicle-cli/src/commands/help.rs
@@ -92,7 +92,10 @@ const COMMANDS: &[CommandItem] = &[
    CommandItem::Lexopt(crate::commands::rad_self::HELP),
    CommandItem::Lexopt(crate::commands::seed::HELP),
    CommandItem::Lexopt(crate::commands::follow::HELP),
-
    CommandItem::Lexopt(crate::commands::unblock::HELP),
+
    CommandItem::Clap {
+
        name: "unblock",
+
        about: crate::commands::unblock::ABOUT,
+
    },
    CommandItem::Clap {
        name: "unfollow",
        about: crate::commands::unfollow::ABOUT,
modified crates/radicle-cli/src/commands/unblock.rs
@@ -1,98 +1,25 @@
-
use std::ffi::OsString;
-

-
use radicle::prelude::{NodeId, RepoId};
+
mod args;

use crate::terminal as term;
-
use crate::terminal::args;
-
use crate::terminal::args::{Args, Error, Help};
-

-
pub const HELP: Help = Help {
-
    name: "unblock",
-
    description: "Unblock repositories or nodes to allow them to be seeded or followed",
-
    version: env!("RADICLE_VERSION"),
-
    usage: r#"
-
Usage
-

-
    rad unblock <rid> [<option>...]
-
    rad unblock <nid> [<option>...]
-

-
    Unblock a repository or remote to allow it to be seeded or followed.
-

-
Options

-
    --help          Print help
-
"#,
-
};
+
use term::args::BlockTarget;

-
enum Target {
-
    Node(NodeId),
-
    Repo(RepoId),
-
}
-

-
impl std::fmt::Display for Target {
-
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-
        match self {
-
            Self::Node(nid) => nid.fmt(f),
-
            Self::Repo(rid) => rid.fmt(f),
-
        }
-
    }
-
}
-

-
pub struct Options {
-
    target: Target,
-
}
-

-
impl Args for Options {
-
    fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
-
        use lexopt::prelude::*;
-

-
        let mut parser = lexopt::Parser::from_args(args);
-
        let mut target = None;
-

-
        while let Some(arg) = parser.next()? {
-
            match arg {
-
                Long("help") | Short('h') => {
-
                    return Err(Error::Help.into());
-
                }
-
                Value(val) if target.is_none() => {
-
                    if let Ok(rid) = args::rid(&val) {
-
                        target = Some(Target::Repo(rid));
-
                    } else if let Ok(nid) = args::nid(&val) {
-
                        target = Some(Target::Node(nid));
-
                    } else {
-
                        anyhow::bail!(
-
                            "invalid repository or remote specified, see `rad unblock --help`"
-
                        )
-
                    }
-
                }
-
                _ => anyhow::bail!(arg.unexpected()),
-
            }
-
        }
-

-
        Ok((
-
            Options {
-
                target: target.ok_or(anyhow::anyhow!(
-
                    "a repository or remote to unblock must be specified, see `rad unblock --help`"
-
                ))?,
-
            },
-
            vec![],
-
        ))
-
    }
-
}
+
pub use args::Args;
+
pub(crate) use args::ABOUT;

-
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
+
pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
    let mut policies = profile.policies_mut()?;

-
    let updated = match options.target {
-
        Target::Node(nid) => policies.unblock_nid(&nid)?,
-
        Target::Repo(rid) => policies.unblock_rid(&rid)?,
+
    let updated = match args.target {
+
        BlockTarget::Node(nid) => policies.unblock_nid(&nid)?,
+
        BlockTarget::Repo(rid) => policies.unblock_rid(&rid)?,
    };

    if updated {
-
        term::success!("The 'block' policy for {} is removed", options.target);
+
        term::success!("The 'block' policy for {} is removed", args.target);
    } else {
-
        term::info!("No 'block' policy exists for {}", options.target)
+
        term::info!("No 'block' policy exists for {}", args.target)
    }
    Ok(())
}
added crates/radicle-cli/src/commands/unblock/args.rs
@@ -0,0 +1,15 @@
+
use clap::Parser;
+

+
use crate::terminal::args::BlockTarget;
+

+
pub(crate) const ABOUT: &str =
+
    "Unblock repositories or nodes to allow them to be seeded or followed";
+

+
#[derive(Parser, Debug)]
+
#[command(about = ABOUT, disable_version_flag = true)]
+
pub struct Args {
+
    /// A Repository ID or Node ID to allow to be seeded or followed
+
    ///
+
    /// [example values: rad:z3Tr6bC7ctEg2EHmLvknUr29mEDLH, z6MkiswaKJ85vafhffCGBu2gdBsYoDAyHVBWRxL3j297fwS9]
+
    pub(super) target: BlockTarget,
+
}
modified crates/radicle-cli/src/main.rs
@@ -69,6 +69,7 @@ enum Commands {
    Path(path::Args),
    Publish(publish::Args),
    Stats(stats::Args),
+
    Unblock(unblock::Args),
    Unfollow(unfollow::Args),
    Unseed(unseed::Args),
    Watch(watch::Args),
@@ -309,11 +310,9 @@ pub(crate) fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyho
            term::run_command_args::<seed::Options, _>(seed::HELP, seed::run, args.to_vec());
        }
        "unblock" => {
-
            term::run_command_args::<unblock::Options, _>(
-
                unblock::HELP,
-
                unblock::run,
-
                args.to_vec(),
-
            );
+
            if let Some(Commands::Unblock(args)) = CliArgs::parse().command {
+
                term::run_command_fn(unblock::run, args);
+
            }
        }
        "unfollow" => {
            if let Some(Commands::Unfollow(args)) = CliArgs::parse().command {