diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-06-21 17:00:58 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2008-06-21 17:00:58 +0200 |
commit | 7fa5ff9745fa4a8dfde272a736554e58f4acd0b7 (patch) | |
tree | 6ec3553d28c57e41877b275f660f69e528d5795d | |
parent | 304b55877c6a9876a0dc8b22c3d122ce057f1eaa (diff) | |
download | ndim-git-utils-7fa5ff9745fa4a8dfde272a736554e58f4acd0b7.tar.gz ndim-git-utils-7fa5ff9745fa4a8dfde272a736554e58f4acd0b7.tar.xz ndim-git-utils-7fa5ff9745fa4a8dfde272a736554e58f4acd0b7.zip |
nbb: Check command parameters
-rw-r--r-- | nbb/nbb_lib.in | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/nbb/nbb_lib.in b/nbb/nbb_lib.in index 17931ee..f1356de 100644 --- a/nbb/nbb_lib.in +++ b/nbb/nbb_lib.in @@ -136,6 +136,16 @@ class AbstractConfig(object): return os.path.join(self.srcdir, "_install", self.nick) +class CommandLineError(Exception): + def __init__(self, message, *args): + if args: + self.msg = message % args + else: + self.msg = message + def __str__(self): + return "Command line error: %s" % self.msg + + class DuplicatePluginName(Exception): pass @@ -268,7 +278,7 @@ class Command(object): Short (less than 50 chars) command summary line validate_args(*args, **kwargs) function - Must raise FIXME() if it encounters invalid arguments in cmdargs + Must raise CommandLineError() if it encounters invalid arguments in cmdargs run() function Actually run the function @@ -292,6 +302,8 @@ class Command(object): print "Command: ", self.name print "*args: ", args print "**kwargs:", kwargs + if len(args) > 0: + raise CommandLineError("'%s' command takes no parameters", self.name) def __str__(self): return "Command(%s, %s)" % (self.cmd_name, self.cmdargs) @@ -486,8 +498,12 @@ class AutomakeSourceTree(BSSourceTree): class NBB_Command(object): def __init__(self, cmd, cmdargs): if Command.plugins.has_key(cmd): - c = Command.plugins[cmd](*cmdargs) - c.run() + try: + c = Command.plugins[cmd](*cmdargs) + c.run() + except CommandLineError, e: + print "%(prog)s: Fatal:" % (outdict), e + sys.exit(2) else: print "Fatal: Unknown command '%s'" % cmd raise NotImplementedError() |