Added exceptions for missing commands, handled -, plugin command exec
authorAaron Bentley <abentley@panoramicfeedback.com>
Fri, 11 Mar 2005 19:28:15 +0000 (19:28 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Fri, 11 Mar 2005 19:28:15 +0000 (19:28 +0000)
be
libbe/cmdutil.py

diff --git a/be b/be
index 3c6c36dbfd411ba264df6821f6862ef79df59c2d..93f8e48e32665a54066391ab88dd8971cd4168a3 100755 (executable)
--- a/be
+++ b/be
@@ -40,15 +40,7 @@ Supported commands"""
 else:
     try:
         try:
-            cmd = {
-                "list": becommands.list.execute,
-                "show": becommands.show.execute,
-                "set-root": becommands.set_root.execute,
-                "new": becommands.new.execute,
-                "close": becommands.close.execute,
-                "open": becommands.open.execute,
-                "severity": becommands.severity.execute,
-            }[sys.argv[1]]
+            execute(sys.argv[1], sys.argv[2:])
         except KeyError, e:
             raise UserError("Unknown command \"%s\"" % e.args[0])
         cmd(sys.argv[2:])
index 77f0dfbe9b3b316e224fad5eb6f0a6828b5de20a..891e2738c7e2ef32172de0741f7f2df7574af89a 100644 (file)
@@ -51,10 +51,17 @@ def bug_summary(bug, bugs):
              bug.summary)
 
 def iter_commands():
-    return plugin.iter_plugins("becommands")
+    for name, module in plugin.iter_plugins("becommands"):
+        yield name.replace("_", "-"), module
+
+def get_command(command_name):
+    cmd = plugin.get_plugin("becommands", command_name.replace("-", "_"))
+    if cmd is None:
+        raise UserError("Unknown command %s" % command_name)
+    return cmd
 
 def execute(cmd, args):
-    return plugin.get_plugin("becommands", cmd).execute(args)
+    return get_command(cmd).execute(args)
 
 def help(cmd, args):
-    return plugin.get_plugin("becommands", cmd).help()
+    return get_command(cmd).help()