Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Add common value parser for NID / DID
Erik Kundt committed 6 months ago
commit 1cc17075693170297302859e2b3fd3a0b81df7bd
parent 634866889f30736ef07839796ffd3482239121fb
1 file changed +15 -0
modified crates/radicle-cli/src/terminal/args.rs
@@ -244,6 +244,21 @@ impl std::fmt::Display for BlockTarget {
    }
}

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

+
pub(crate) 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 })
+
    })
+
}
+

#[derive(Clone, Debug)]
pub(crate) struct ScopeParser;