Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Simplify error message and give examples
Erik Kundt committed 7 months ago
commit cb8e011b1342bb7e325b58c3565860ae485bed87
parent 5c312bfef3af2df83103db579cf269ab5df7626c
1 file changed +16 -20
modified crates/radicle-cli/src/commands/block/args.rs
@@ -11,25 +11,6 @@ pub(super) enum Target {
    Repo(RepoId),
}

-
#[derive(Debug, Error)]
-
#[error("invalid repository or node specified (RID parsing failed with: '{repo}', NID parsing failed with: '{node}'))")]
-
pub(super) struct ParseTargetError {
-
    repo: radicle::identity::IdError,
-
    node: radicle::crypto::PublicKeyError,
-
}
-

-
impl std::str::FromStr for Target {
-
    type Err = ParseTargetError;
-

-
    fn from_str(val: &str) -> Result<Self, Self::Err> {
-
        val.parse::<RepoId>().map(Target::Repo).or_else(|repo| {
-
            val.parse::<NodeId>()
-
                .map(Target::Node)
-
                .map_err(|node| ParseTargetError { repo, node })
-
        })
-
    }
-
}
-

impl std::fmt::Display for Target {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
@@ -39,10 +20,25 @@ impl std::fmt::Display for Target {
    }
}

+
#[derive(Debug, Error)]
+
#[error("could not parse value as Repository ID or Node ID")]
+
pub(super) struct ParseTargetError {}
+

+
fn parse_target(value: &str) -> Result<Target, ParseTargetError> {
+
    value.parse::<RepoId>().map(Target::Repo).or(value
+
        .parse::<NodeId>()
+
        .map(Target::Node)
+
        .map_err(|_| ParseTargetError {}))
+
}
+

#[derive(Parser, Debug)]
#[command(about = ABOUT, disable_version_flag = true)]
pub struct Args {
    /// A Repository ID or Node ID to block from seeding or following (respectively)
-
    #[arg(value_name = "RID|NID")]
+
    ///
+
    /// Example values:
+
    /// - z6MksmpU5b1dS7oaqF2bHXhQi1DWy2hB7Mh9CuN7y1DN6QSz (Node ID)
+
    /// - rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5 (Repository ID)
+
    #[arg(value_name = "RID|NID", value_parser = parse_target, verbatim_doc_comment)]
    pub(super) target: Target,
}