changeset 43898:023ad45e2fd2

releasenotes: extract helper for checking for incompatible arguments This patch extracts a new check_incompatible_arguments() function similar to check_at_most_one_arg(). The difference is that the new function is for checking for arguments that are disallowed together with some other argument but not mutually exclusive among themselves. Differential Revision: https://phab.mercurial-scm.org/D7639
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 12 Dec 2019 22:30:59 -0800
parents dda49ec2b54a
children fff21278554b
files hgext/releasenotes.py mercurial/cmdutil.py
diffstat 2 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/releasenotes.py	Thu Dec 12 15:51:09 2019 -0800
+++ b/hgext/releasenotes.py	Thu Dec 12 22:30:59 2019 -0800
@@ -20,6 +20,7 @@
 from mercurial.i18n import _
 from mercurial.pycompat import open
 from mercurial import (
+    cmdutil,
     config,
     error,
     minirst,
@@ -653,14 +654,9 @@
     opts = pycompat.byteskwargs(opts)
     sections = releasenotessections(ui, repo)
 
-    listflag = opts.get(b'list')
+    cmdutil.check_incompatible_arguments(opts, b'list', b'rev', b'check')
 
-    if listflag and opts.get(b'rev'):
-        raise error.Abort(_(b'cannot use both \'--list\' and \'--rev\''))
-    if listflag and opts.get(b'check'):
-        raise error.Abort(_(b'cannot use both \'--list\' and \'--check\''))
-
-    if listflag:
+    if opts.get(b'list'):
         return _getadmonitionlist(ui, sections)
 
     rev = opts.get(b'rev')
--- a/mercurial/cmdutil.py	Thu Dec 12 15:51:09 2019 -0800
+++ b/mercurial/cmdutil.py	Thu Dec 12 22:30:59 2019 -0800
@@ -272,6 +272,16 @@
             previous = x
 
 
+def check_incompatible_arguments(opts, first, *others):
+    """abort if the first argument is given along with any of the others
+
+    Unlike check_at_most_one_arg(), `others` are not mutually exclusive
+    among themselves.
+    """
+    for other in others:
+        check_at_most_one_arg(opts, first, other)
+
+
 def resolvecommitoptions(ui, opts):
     """modify commit options dict to handle related options