@@ -167,6 +167,21 @@ def die(msg):
167
167
sys .stderr .write (msg + "\n " )
168
168
sys .exit (1 )
169
169
170
+ def prompt (prompt_text ):
171
+ """ Prompt the user to choose one of the choices
172
+
173
+ Choices are identified in the prompt_text by square brackets around
174
+ a single letter option.
175
+ """
176
+ choices = set (m .group (1 ) for m in re .finditer (r"\[(.)\]" , prompt_text ))
177
+ while True :
178
+ response = raw_input (prompt_text ).strip ().lower ()
179
+ if not response :
180
+ continue
181
+ response = response [0 ]
182
+ if response in choices :
183
+ return response
184
+
170
185
def write_pipe (c , stdin ):
171
186
if verbose :
172
187
sys .stderr .write ('Writing pipe: %s\n ' % str (c ))
@@ -1784,12 +1799,11 @@ def edit_template(self, template_file):
1784
1799
if os .stat (template_file ).st_mtime > mtime :
1785
1800
return True
1786
1801
1787
- while True :
1788
- response = raw_input ("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) " )
1789
- if response == 'y' :
1790
- return True
1791
- if response == 'n' :
1792
- return False
1802
+ response = prompt ("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) " )
1803
+ if response == 'y' :
1804
+ return True
1805
+ if response == 'n' :
1806
+ return False
1793
1807
1794
1808
def get_diff_description (self , editedFiles , filesToAdd , symlinks ):
1795
1809
# diff
@@ -2351,31 +2365,22 @@ def run(self, args):
2351
2365
" --prepare-p4-only" )
2352
2366
break
2353
2367
if i < last :
2354
- quit = False
2355
- while True :
2356
- # prompt for what to do, or use the option/variable
2357
- if self .conflict_behavior == "ask" :
2358
- print ("What do you want to do?" )
2359
- response = raw_input ("[s]kip this commit but apply"
2360
- " the rest, or [q]uit? " )
2361
- if not response :
2362
- continue
2363
- elif self .conflict_behavior == "skip" :
2364
- response = "s"
2365
- elif self .conflict_behavior == "quit" :
2366
- response = "q"
2367
- else :
2368
- die ("Unknown conflict_behavior '%s'" %
2369
- self .conflict_behavior )
2370
-
2371
- if response [0 ] == "s" :
2372
- print ("Skipping this commit, but applying the rest" )
2373
- break
2374
- if response [0 ] == "q" :
2375
- print ("Quitting" )
2376
- quit = True
2377
- break
2378
- if quit :
2368
+ # prompt for what to do, or use the option/variable
2369
+ if self .conflict_behavior == "ask" :
2370
+ print ("What do you want to do?" )
2371
+ response = prompt ("[s]kip this commit but apply the rest, or [q]uit? " )
2372
+ elif self .conflict_behavior == "skip" :
2373
+ response = "s"
2374
+ elif self .conflict_behavior == "quit" :
2375
+ response = "q"
2376
+ else :
2377
+ die ("Unknown conflict_behavior '%s'" %
2378
+ self .conflict_behavior )
2379
+
2380
+ if response == "s" :
2381
+ print ("Skipping this commit, but applying the rest" )
2382
+ if response == "q" :
2383
+ print ("Quitting" )
2379
2384
break
2380
2385
2381
2386
chdir (self .oldWorkingDirectory )
@@ -4146,7 +4151,12 @@ def main():
4146
4151
description = cmd .description ,
4147
4152
formatter = HelpFormatter ())
4148
4153
4149
- (cmd , args ) = parser .parse_args (sys .argv [2 :], cmd );
4154
+ try :
4155
+ (cmd , args ) = parser .parse_args (sys .argv [2 :], cmd );
4156
+ except :
4157
+ parser .print_help ()
4158
+ raise
4159
+
4150
4160
global verbose
4151
4161
verbose = cmd .verbose
4152
4162
if cmd .needsGit :
0 commit comments