Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 43892:d587937600be
clone: extract helper for checking mutually exclusive args
We have some duplicated code for aborting if the user provided
mutually exclusive arguments. Extensions surely have more such
code. We also have duplicated translations and inconsistent output in
this area.
This patch introduces a simpler helper for checking if more than one
option among a given set was given on the command line. I've made the
clone code call the function to show that it works.
The function has no good way of checking arguments with hyphens in
them. I'll add that later if necessary. The function still won't be
applicable in all cases, but I think it's still better than nothing.
Differential Revision: https://phab.mercurial-scm.org/D7633
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 12 Dec 2019 15:16:13 -0800 |
parents | aac921f54554 |
children | 2e672ccc2220 |
comparison
equal
deleted
inserted
replaced
43891:7eb6a2680ae6 | 43892:d587937600be |
---|---|
256 ] | 256 ] |
257 | 257 |
258 # special string such that everything below this line will be ingored in the | 258 # special string such that everything below this line will be ingored in the |
259 # editor text | 259 # editor text |
260 _linebelow = b"^HG: ------------------------ >8 ------------------------$" | 260 _linebelow = b"^HG: ------------------------ >8 ------------------------$" |
261 | |
262 | |
263 def check_at_most_one_arg(opts, *args): | |
264 """abort if more than one of the arguments are in opts""" | |
265 previous = None | |
266 for x in args: | |
267 if opts.get(x): | |
268 if previous: | |
269 raise error.Abort( | |
270 _(b'cannot specify both --%s and --%s') % (previous, x) | |
271 ) | |
272 previous = x | |
261 | 273 |
262 | 274 |
263 def resolvecommitoptions(ui, opts): | 275 def resolvecommitoptions(ui, opts): |
264 """modify commit options dict to handle related options | 276 """modify commit options dict to handle related options |
265 | 277 |