Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: fallible comment selector
Fintan Halpenny committed 1 year ago
commit 2af090ea1eb6ac806d9598f657c60c5327c12143
parent 7eb07e1b4d57ddb4660d0363691877fe893af044
2 files changed +11 -8
modified radicle-cli/src/commands/issue.rs
@@ -591,10 +591,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            let id = id.resolve(&repo.backend)?;
            if let Ok(mut issue) = issues.get_mut(&id) {
                let signer = term::signer(&profile)?;
-
                let comment_id = comment_id.unwrap_or_else(|| {
-
                    let (comment_id, _) = term::io::comment_select(&issue).unwrap();
-
                    *comment_id
-
                });
+
                let comment_id = match comment_id {
+
                    Some(cid) => cid,
+
                    None => *term::io::comment_select(&issue).map(|(cid, _)| cid)?,
+
                };
                issue.react(comment_id, reaction, true, &signer)?;
            }
        }
modified radicle-cli/src/terminal/io.rs
@@ -1,3 +1,4 @@
+
use anyhow::anyhow;
use radicle::cob::issue::Issue;
use radicle::cob::thread::{Comment, CommentId};
use radicle::crypto::ssh::keystore::MemorySigner;
@@ -63,7 +64,7 @@ pub fn signer(profile: &Profile) -> anyhow::Result<Box<dyn Signer>> {
    Ok(signer.boxed())
}

-
pub fn comment_select(issue: &Issue) -> Option<(&CommentId, &Comment)> {
+
pub fn comment_select(issue: &Issue) -> anyhow::Result<(&CommentId, &Comment)> {
    let comments = issue.comments().collect::<Vec<_>>();
    let selection = Select::new(
        "Which comment do you want to react to?",
@@ -71,8 +72,10 @@ pub fn comment_select(issue: &Issue) -> Option<(&CommentId, &Comment)> {
    )
    .with_render_config(*CONFIG)
    .with_formatter(&|i| comments[i.index].1.body().to_owned())
-
    .prompt()
-
    .ok()?;
+
    .prompt()?;

-
    comments.get(selection).copied()
+
    comments
+
        .get(selection)
+
        .copied()
+
        .ok_or(anyhow!("failed to perform comment selection"))
}