Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Fix `Message::get` bug
Alexis Sellier committed 3 years ago
commit 60fc50644fd6bf3fc8833d434777852ea17c2bea
parent 44298df48f603f0b2df9aa4343d6ded1e5277b34
5 files changed +7 -11
modified radicle-cli/src/commands/comment.rs
@@ -93,7 +93,7 @@ fn comment(
    repo: &storage::git::Repository,
    signer: impl Signer,
) -> anyhow::Result<()> {
-
    let message = options.message.clone().get("Enter a comment...");
+
    let message = options.message.clone().get("Enter a comment...")?;
    if message.is_empty() {
        return Ok(());
    }
modified radicle-cli/src/commands/patch/create.rs
@@ -34,7 +34,7 @@ pub fn handle_patch_message(
    let commit_message = head_commit
        .message()
        .ok_or(anyhow!("commit summary is not valid UTF-8; aborting"))?;
-
    let message = message.get(&format!("{commit_message}{PATCH_MSG}"));
+
    let message = message.get(&format!("{commit_message}{PATCH_MSG}"))?;
    let message = message.replace(PATCH_MSG.trim(), ""); // Delete help message.
    let (title, description) = message.split_once("\n\n").unwrap_or((&message, ""));
    let (title, description) = (title.trim(), description.trim());
modified radicle-cli/src/commands/patch/update.rs
@@ -100,7 +100,7 @@ pub fn run(

    let head_oid = branch_oid(&head_branch)?;
    let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
-
    let message = message.get(REVISION_MSG);
+
    let message = message.get(REVISION_MSG)?;
    let message = message.replace(REVISION_MSG.trim(), "");
    let message = message.trim();
    let signer = term::signer(profile)?;
modified radicle-cli/src/commands/review.rs
@@ -144,7 +144,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
        .revisions()
        .nth(revision_ix)
        .ok_or_else(|| anyhow!("revision R{} does not exist", revision_ix))?;
-
    let message = options.message.get(REVIEW_HELP_MSG);
+
    let message = options.message.get(REVIEW_HELP_MSG)?;
    let message = message.replace(REVIEW_HELP_MSG.trim(), "");
    let message = if message.is_empty() {
        None
modified radicle-cli/src/terminal/patch.rs
@@ -16,20 +16,16 @@ pub enum Message {

impl Message {
    /// Get the `Message` as a string according to the method.
-
    pub fn get(self, help: &str) -> String {
+
    pub fn get(self, help: &str) -> std::io::Result<String> {
        let comment = match self {
-
            Message::Edit => term::Editor::new()
-
                .extension("markdown")
-
                .edit(help)
-
                .ok()
-
                .flatten(),
+
            Message::Edit => term::Editor::new().extension("markdown").edit(help)?,
            Message::Blank => None,
            Message::Text(c) => Some(c),
        };
        let comment = comment.unwrap_or_default();
        let comment = comment.trim();

-
        comment.to_owned()
+
        Ok(comment.to_owned())
    }

    pub fn append(&mut self, arg: &str) {