From: Junio C Hamano <gitster@pobox.com>
To: "Ben Keene via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Ben Keene <seraphire@gmail.com>
Subject: Re: [PATCH 1/3] git-p4: [usability] yes/no prompts should sanitize user text
Date: Mon, 09 Dec 2019 14:00:55 -0800 [thread overview]
Message-ID: <xmqqimmptazs.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <e721cdaa008263b896c1d162e411c4e7a04c5710.1575901009.git.gitgitgadget@gmail.com> (Ben Keene via GitGitGadget's message of "Mon, 09 Dec 2019 14:16:47 +0000")
"Ben Keene via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Ben Keene <seraphire@gmail.com>
>
> When prompting the user interactively for direction, the tests are
> not forgiving of user input format.
>
> For example, the first query asks for a yes/no response. If the user
> enters the full word "yes" or "no" or enters a capital "Y" the test
> will fail.
>
> Create a new function, prompt(prompt_text, choices) where
> * promt_text is the text prompt for the user
> * is a list of lower-case, single letter choices.
> This new function must prompt the user for input and sanitize it by
> converting the response to a lower case string, trimming leading and
> trailing spaces, and checking if the first character is in the list
> of choices. If it is, return the first letter.
>
> Change the current references to raw_input() to use this new function.
>
> Signed-off-by: Ben Keene <seraphire@gmail.com>
> ---
> git-p4.py | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 60c73b6a37..0fa562fac9 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -167,6 +167,17 @@ def die(msg):
> sys.stderr.write(msg + "\n")
> sys.exit(1)
>
> +def prompt(prompt_text, choices = []):
> + """ Prompt the user to choose one of the choices
> + """
> + while True:
> + response = raw_input(prompt_text).strip().lower()
> + if len(response) == 0:
> + continue
> + response = response[0]
> + if response in choices:
> + return response
I think this is a strict improvement compared to the original, but
the new loop makes me wonder if we need to worry more about getting
EOF while calling raw_input() here. I am assuming that we would get
EOFError either way so this is no worse/better than the status quo,
and we can keep it outside the topic (even though it may be a good
candidate for a low-hanging fruit for newbies).
> def write_pipe(c, stdin):
> if verbose:
> sys.stderr.write('Writing pipe: %s\n' % str(c))
> @@ -1779,7 +1790,7 @@ def edit_template(self, template_file):
> return True
>
> while True:
> - response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
> + response = prompt("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ", ["y", "n"])
> if response == 'y':
> return True
> if response == 'n':
> @@ -2350,8 +2361,8 @@ def run(self, args):
> # prompt for what to do, or use the option/variable
> if self.conflict_behavior == "ask":
> print("What do you want to do?")
> - response = raw_input("[s]kip this commit but apply"
> - " the rest, or [q]uit? ")
> + response = prompt("[s]kip this commit but apply"
> + " the rest, or [q]uit? ", ["s", "q"])
> if not response:
> continue
> elif self.conflict_behavior == "skip":
next prev parent reply other threads:[~2019-12-09 22:01 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-09 14:16 [PATCH 0/3] git-p4: Usability enhancements Ben Keene via GitGitGadget
2019-12-09 14:16 ` [PATCH 1/3] git-p4: [usability] yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-09 22:00 ` Junio C Hamano [this message]
2019-12-10 14:26 ` Ben Keene
2019-12-09 14:16 ` [PATCH 2/3] git-p4: [usability] RCS Keyword failure should suggest help Ben Keene via GitGitGadget
2019-12-09 22:22 ` Junio C Hamano
2019-12-09 14:16 ` [PATCH 3/3] git-p4: [usability] Show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-09 22:24 ` Junio C Hamano
2019-12-09 22:06 ` [PATCH 0/3] git-p4: Usability enhancements Junio C Hamano
2019-12-10 15:22 ` [PATCH v2 0/4] " Ben Keene via GitGitGadget
2019-12-10 15:22 ` [PATCH v2 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-11 11:52 ` Denton Liu
2019-12-11 11:59 ` Denton Liu
2019-12-10 15:22 ` [PATCH v2 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-10 15:22 ` [PATCH v2 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-10 15:22 ` [PATCH v2 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-11 11:29 ` Denton Liu
2019-12-11 9:43 ` [PATCH v2 0/4] git-p4: Usability enhancements Luke Diamand
2019-12-12 19:46 ` [PATCH v3 " Ben Keene via GitGitGadget
2019-12-12 19:46 ` [PATCH v3 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-13 1:45 ` Denton Liu
2019-12-13 13:42 ` Ben Keene
2019-12-13 19:46 ` Junio C Hamano
2019-12-15 20:30 ` Johannes Schindelin
2019-12-16 17:54 ` Junio C Hamano
2019-12-16 19:11 ` Ben Keene
2019-12-12 19:46 ` [PATCH v3 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-12 19:46 ` [PATCH v3 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-12 19:46 ` [PATCH v3 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-13 13:57 ` [PATCH v4 0/4] git-p4: Usability enhancements Ben Keene via GitGitGadget
2019-12-13 13:57 ` [PATCH v4 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-13 22:54 ` Denton Liu
2019-12-16 13:53 ` Ben Keene
2019-12-13 13:57 ` [PATCH v4 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-13 13:58 ` [PATCH v4 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-13 13:58 ` [PATCH v4 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-16 14:02 ` [PATCH v5 0/4] git-p4: Usability enhancements Ben Keene via GitGitGadget
2019-12-16 14:02 ` [PATCH v5 1/4] git-p4: yes/no prompts should sanitize user text Ben Keene via GitGitGadget
2019-12-16 14:02 ` [PATCH v5 2/4] git-p4: show detailed help when parsing options fail Ben Keene via GitGitGadget
2019-12-16 14:02 ` [PATCH v5 3/4] git-p4: wrap patchRCSKeywords test to revert changes on failure Ben Keene via GitGitGadget
2019-12-16 14:02 ` [PATCH v5 4/4] git-p4: failure because of RCS keywords should show help Ben Keene via GitGitGadget
2019-12-16 20:39 ` [PATCH v5 0/4] git-p4: Usability enhancements Junio C Hamano
2019-12-21 10:19 ` Luke Diamand
2019-12-25 19:13 ` Junio C Hamano
2020-01-02 13:50 ` Ben Keene
2020-01-02 21:44 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqimmptazs.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=seraphire@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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).