Merge branch 'bk/p4-misc-usability'
Miscellaneous small UX improvements on "git-p4". * bk/p4-misc-usability: git-p4: show detailed help when parsing options fail git-p4: yes/no prompts should sanitize user text
This commit is contained in:
commit
bc855232bc
72
git-p4.py
72
git-p4.py
@ -167,6 +167,21 @@ def die(msg):
|
|||||||
sys.stderr.write(msg + "\n")
|
sys.stderr.write(msg + "\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def prompt(prompt_text):
|
||||||
|
""" Prompt the user to choose one of the choices
|
||||||
|
|
||||||
|
Choices are identified in the prompt_text by square brackets around
|
||||||
|
a single letter option.
|
||||||
|
"""
|
||||||
|
choices = set(m.group(1) for m in re.finditer(r"\[(.)\]", prompt_text))
|
||||||
|
while True:
|
||||||
|
response = raw_input(prompt_text).strip().lower()
|
||||||
|
if not response:
|
||||||
|
continue
|
||||||
|
response = response[0]
|
||||||
|
if response in choices:
|
||||||
|
return response
|
||||||
|
|
||||||
def write_pipe(c, stdin):
|
def write_pipe(c, stdin):
|
||||||
if verbose:
|
if verbose:
|
||||||
sys.stderr.write('Writing pipe: %s\n' % str(c))
|
sys.stderr.write('Writing pipe: %s\n' % str(c))
|
||||||
@ -1784,12 +1799,11 @@ class P4Submit(Command, P4UserMap):
|
|||||||
if os.stat(template_file).st_mtime > mtime:
|
if os.stat(template_file).st_mtime > mtime:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
while True:
|
response = prompt("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
|
||||||
response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
|
if response == 'y':
|
||||||
if response == 'y':
|
return True
|
||||||
return True
|
if response == 'n':
|
||||||
if response == 'n':
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def get_diff_description(self, editedFiles, filesToAdd, symlinks):
|
def get_diff_description(self, editedFiles, filesToAdd, symlinks):
|
||||||
# diff
|
# diff
|
||||||
@ -2351,31 +2365,22 @@ class P4Submit(Command, P4UserMap):
|
|||||||
" --prepare-p4-only")
|
" --prepare-p4-only")
|
||||||
break
|
break
|
||||||
if i < last:
|
if i < last:
|
||||||
quit = False
|
# prompt for what to do, or use the option/variable
|
||||||
while True:
|
if self.conflict_behavior == "ask":
|
||||||
# prompt for what to do, or use the option/variable
|
print("What do you want to do?")
|
||||||
if self.conflict_behavior == "ask":
|
response = prompt("[s]kip this commit but apply the rest, or [q]uit? ")
|
||||||
print("What do you want to do?")
|
elif self.conflict_behavior == "skip":
|
||||||
response = raw_input("[s]kip this commit but apply"
|
response = "s"
|
||||||
" the rest, or [q]uit? ")
|
elif self.conflict_behavior == "quit":
|
||||||
if not response:
|
response = "q"
|
||||||
continue
|
else:
|
||||||
elif self.conflict_behavior == "skip":
|
die("Unknown conflict_behavior '%s'" %
|
||||||
response = "s"
|
self.conflict_behavior)
|
||||||
elif self.conflict_behavior == "quit":
|
|
||||||
response = "q"
|
|
||||||
else:
|
|
||||||
die("Unknown conflict_behavior '%s'" %
|
|
||||||
self.conflict_behavior)
|
|
||||||
|
|
||||||
if response[0] == "s":
|
if response == "s":
|
||||||
print("Skipping this commit, but applying the rest")
|
print("Skipping this commit, but applying the rest")
|
||||||
break
|
if response == "q":
|
||||||
if response[0] == "q":
|
print("Quitting")
|
||||||
print("Quitting")
|
|
||||||
quit = True
|
|
||||||
break
|
|
||||||
if quit:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
chdir(self.oldWorkingDirectory)
|
chdir(self.oldWorkingDirectory)
|
||||||
@ -4146,7 +4151,12 @@ def main():
|
|||||||
description = cmd.description,
|
description = cmd.description,
|
||||||
formatter = HelpFormatter())
|
formatter = HelpFormatter())
|
||||||
|
|
||||||
(cmd, args) = parser.parse_args(sys.argv[2:], cmd);
|
try:
|
||||||
|
(cmd, args) = parser.parse_args(sys.argv[2:], cmd);
|
||||||
|
except:
|
||||||
|
parser.print_help()
|
||||||
|
raise
|
||||||
|
|
||||||
global verbose
|
global verbose
|
||||||
verbose = cmd.verbose
|
verbose = cmd.verbose
|
||||||
if cmd.needsGit:
|
if cmd.needsGit:
|
||||||
|
Loading…
Reference in New Issue
Block a user