summaryrefslogtreecommitdiff
path: root/clcommands.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2011-01-28 15:12:51 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2011-01-28 15:12:51 +0100
commit411a7146c2bd30a6cab6756b1dbae0a51e85f830 (patch)
treee27520166f46e5b892bea0926a56d40c6450a7ca /clcommands.py
parent8c843f5be3aef98119729ea6469c8377d75ec929 (diff)
downloadlogilab-common-411a7146c2bd30a6cab6756b1dbae0a51e85f830.tar.gz
unless asked explicitly, check we don't register a same command twice
Diffstat (limited to 'clcommands.py')
-rw-r--r--clcommands.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/clcommands.py b/clcommands.py
index 92a566a..b8f3806 100644
--- a/clcommands.py
+++ b/clcommands.py
@@ -76,7 +76,8 @@ class CommandLine(dict):
`logging.getLogger(self.pgm))`
"""
def __init__(self, pgm=None, doc=None, copyright=None, version=None,
- rcfile=None, logthreshold=logging.ERROR):
+ rcfile=None, logthreshold=logging.ERROR,
+ check_duplicated_command=True):
if pgm is None:
pgm = basename(sys.argv[0])
self.pgm = pgm
@@ -86,9 +87,12 @@ class CommandLine(dict):
self.rcfile = rcfile
self.logger = None
self.logthreshold = logthreshold
+ self.check_duplicated_command = check_duplicated_command
- def register(self, cls):
+ def register(self, cls, force=False):
"""register the given :class:`Command` subclass"""
+ assert not self.check_duplicated_command or force or not cls.name in self, \
+ 'a command %s is already defined' % cls.name
self[cls.name] = cls
def run(self, args):