mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 02:20:43 +08:00
cli: Add common value parser for NID / DID
This commit is contained in:
committed by
Fintan Halpenny
parent
06e22434e1
commit
e488ddb446
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user