radicle_cli/commands/unfollow/
args.rs

1use clap::Parser;
2
3use thiserror::Error;
4
5use radicle::node::NodeId;
6use radicle::prelude::Did;
7
8pub(crate) const ABOUT: &str = "Unfollow a peer";
9
10const LONG_ABOUT: &str = r#"
11The `unfollow` command takes a Node ID, optionally in DID format,
12and removes the follow policy for that peer."#;
13
14#[derive(Debug, Error)]
15#[error("invalid Node ID specified (Node ID parsing failed with: '{nid}', DID parsing failed with: '{did}'))")]
16struct NodeIdParseError {
17    did: radicle::identity::did::DidError,
18    nid: radicle::crypto::PublicKeyError,
19}
20
21fn parse_nid(value: &str) -> Result<NodeId, NodeIdParseError> {
22    value.parse::<Did>().map(NodeId::from).or_else(|did| {
23        value
24            .parse::<NodeId>()
25            .map_err(|nid| NodeIdParseError { nid, did })
26    })
27}
28
29#[derive(Debug, Parser)]
30#[command(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)]
31pub struct Args {
32    /// Node ID (optionally in DID format) of the peer to unfollow
33    #[arg(value_name = "NID", value_parser = parse_nid)]
34    pub(super) nid: NodeId,
35
36    /// Verbose output
37    #[arg(short, long)]
38    pub(super) verbose: bool,
39}