Command dispatcher notifies of ambiguous choice from the given prefix
authorDmitriy Morozov <morozov@cs.duke.edu>
Sat, 24 May 2008 06:23:33 -0400
changeset 6 3f2c0ca0812a
parent 5 35552b6cdc51
child 7 d0e3cd42a3af
Command dispatcher notifies of ambiguous choice from the given prefix
alexandria.py
--- a/alexandria.py	Wed May 21 10:45:31 2008 -0400
+++ b/alexandria.py	Sat May 24 06:23:33 2008 -0400
@@ -212,7 +212,14 @@
     initDatabase(path, not found)
     
     if len(args) == 0: sys.exit()
+    candidates = []
     for cmd in commands:
         func, description = cmd
         if func.__name__.startswith(args[0]):
-            func(args[1:], options)
+            candidates += [func]
+    if len(candidates) > 1:
+        print "Ambiguous choices:",
+        for c in candidates: print c.__name__,
+        print
+    else:
+        candidates[0](args[1:], options)