dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: ew <user@example.com>
To: spew@80x24.org
Subject: [PATCH 1/2] edit: hoist out prompt functions into sub functions
Date: Mon, 23 Sep 2019 03:16:37 +0000	[thread overview]
Message-ID: <20190923031638.14231-1-user@example.com> (raw)

From: Eric Wong <e@80x24.org>

It'll make further changes to factor this into a module easier.
---
 script/public-inbox-edit | 55 +++++++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index 6884fd0c..0962849b 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -119,6 +119,33 @@ $mids
 	$found = { $cid => $to_edit };
 }
 
+sub prompt_retry_continue_quit () {
+	while (1) {
+		print STDERR "(r)etry, (c)ontinue, (q)uit?\n";
+		chomp(my $op = <STDIN> || '');
+		$op = lc($op);
+		return $op if $op eq 'r';
+		exit $? if $op eq 'q';
+		last if $op eq 'c'; # continuing
+		print STDERR "\`$op' not recognized\n";
+	}
+}
+
+sub prompt_extra_from_line () {
+	print STDERR <<'';
+Extra "From " lines detected in new mbox.
+Did you forget to purge the original message from the mbox after editing?
+
+	while (1) {
+		print STDERR "(y)es to re-edit, (n)o to continue\n";
+		chomp(my $op = <STDIN> || '');
+		$op = lc($op);
+		return $op if $op eq 'y';
+		last if $op eq 'n'; # continuing
+		print STDERR "\`$op' not recognized\n";
+	}
+}
+
 my $tmpl = 'public-inbox-edit-XXXXXX';
 foreach my $to_edit (values %$found) {
 	my ($edit_fh, $edit_fn) = tempfile($tmpl, TMPDIR => 1, UNLINK => 1);
@@ -143,15 +170,11 @@ retry_edit:
 			die "E: $editor failed: $?\n";
 		}
 		print STDERR "$editor failed, ";
-		print STDERR "continuing as forced\n" if $opt->{force};
-		while (!$opt->{force}) {
-			print STDERR "(r)etry, (c)ontinue, (q)uit?\n";
-			chomp(my $op = <STDIN> || '');
-			$op = lc($op);
+		if ($opt->{force}) {
+			print STDERR "continuing as forced\n";
+		} else {
+			my $op = prompt_retry_continue_quit();
 			goto retry_edit if $op eq 'r';
-			exit $? if $op eq 'q';
-			last if $op eq 'c'; # continuing
-			print STDERR "\`$op' not recognized\n";
 		}
 	}
 
@@ -168,20 +191,8 @@ retry_edit:
 		# check if user forgot to purge (in mutt) after editing
 		if ($new_raw =~ /^From /sm) {
 			if (-t STDIN) {
-				print STDERR <<'';
-Extra "From " lines detected in new mbox.
-Did you forget to purge the original message from the mbox after editing?
-
-				while (1) {
-					print STDERR <<"";
-(y)es to re-edit, (n)o to continue
-
-					chomp(my $op = <STDIN> || '');
-					$op = lc($op);
-					goto retry_edit if $op eq 'y';
-					last if $op eq 'n'; # continuing
-					print STDERR "\`$op' not recognized\n";
-				}
+				my $op = prompt_extra_from_line();
+				goto retry_edit if $op eq 'y';
 			} else { # non-interactive path
 				# unlikely to happen, as extra From lines are
 				# only a common mistake (for me) with
-- 
EW


             reply	other threads:[~2019-09-23  3:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-23  3:16 ew [this message]
2019-09-23  3:16 ` [PATCH 2/2] wip ew
  -- strict thread matches above, loose matches on Subject: below --
2019-11-03  3:17 [PATCH 1/2] edit: hoist out prompt functions into sub functions Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190923031638.14231-1-user@example.com \
    --to=user@example.com \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).