Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli/unfollow: Improve error message
Erik Kundt committed 7 months ago
commit 035ebf04b54cab8a12a3a12fc11a19dd0de3fda4
parent d9ce078d5617f563af14396dab206b11270061d7
1 file changed +14 -13
modified crates/radicle-cli/src/commands/unfollow/args.rs
@@ -12,25 +12,26 @@ The `unfollow` command takes a Node ID, optionally in DID format,
and removes the follow policy for that peer."#;

#[derive(Debug, Error)]
-
#[error("invalid Node ID specified (Node ID parsing failed with: '{nid}', DID parsing failed with: '{did}'))")]
-
struct NodeIdParseError {
-
    did: radicle::identity::did::DidError,
-
    nid: radicle::crypto::PublicKeyError,
-
}
-

-
fn parse_nid(value: &str) -> Result<NodeId, NodeIdParseError> {
-
    value.parse::<Did>().map(NodeId::from).or_else(|did| {
-
        value
-
            .parse::<NodeId>()
-
            .map_err(|nid| NodeIdParseError { nid, did })
-
    })
+
#[error("could not parse value as Node ID or Node ID in DID format")]
+
struct NodeIdParserError {}
+

+
fn parse_nid(value: &str) -> Result<NodeId, NodeIdParserError> {
+
    value
+
        .parse::<Did>()
+
        .map(NodeId::from)
+
        .or(value.parse::<NodeId>())
+
        .map_err(|_| NodeIdParserError {})
}

#[derive(Debug, Parser)]
#[command(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)]
pub struct Args {
    /// Node ID (optionally in DID format) of the peer to unfollow
-
    #[arg(value_name = "NID", value_parser = parse_nid)]
+
    ///
+
    /// Example values:
+
    /// - z6MksmpU5b1dS7oaqF2bHXhQi1DWy2hB7Mh9CuN7y1DN6QSz
+
    /// - did:key:z6MksmpU5b1dS7oaqF2bHXhQi1DWy2hB7Mh9CuN7y1DN6QSz
+
    #[arg(value_name = "NID", value_parser = parse_nid, verbatim_doc_comment)]
    pub(super) nid: NodeId,

    /// Verbose output