summaryrefslogtreecommitdiff
path: root/clcommands.py
diff options
context:
space:
mode:
authorSylvain <syt@logilab.fr>2006-08-25 15:06:44 +0200
committerSylvain <syt@logilab.fr>2006-08-25 15:06:44 +0200
commit99cad9add0aaedb17a1c52537a002afdab3290b9 (patch)
tree584f62d6ec526fca34a762ca7c85fdf4cffcdf0f /clcommands.py
parent759be5c7f00e7be9390e4b668978cc682a10582e (diff)
downloadlogilab-common-99cad9add0aaedb17a1c52537a002afdab3290b9.tar.gz
see changelog
Diffstat (limited to 'clcommands.py')
-rw-r--r--clcommands.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/clcommands.py b/clcommands.py
index c30e0a6..54bd6ff 100644
--- a/clcommands.py
+++ b/clcommands.py
@@ -40,7 +40,9 @@ class Command(Configuration):
"""base class for command line commands"""
arguments = ''
name = ''
-
+ # max/min args, None meaning unspecified
+ min_args = None
+ max_args = None
def __init__(self, __doc__=None, version=None):
if __doc__:
usage = __doc__ % (self.name, self.arguments,
@@ -48,6 +50,13 @@ class Command(Configuration):
else:
usage = self.__doc__.replace(' ', '')
Configuration.__init__(self, usage=usage, version=version)
+
+ def check_args(self, args):
+ """check command's arguments are provided"""
+ if self.min_args is not None and len(args) < self.min_args:
+ raise BadCommandUsage('missing argument')
+ if self.max_args is not None and len(args) > self.max_args:
+ raise BadCommandUsage('too many arguments')
def run(self, args):
"""run the command with its specific arguments"""
@@ -96,6 +105,7 @@ def cmd_run(cmdname, *args):
except KeyError:
raise BadCommandUsage('no %s command' % cmdname)
args = command.load_command_line_configuration(args)
+ command.check_args(args)
try:
command.run(args)
except KeyboardInterrupt: