pgtool
changeset 101 2a2d0d5df03b
parent 100 d6088dba8fea
child 102 fda45bdfd68d
--- a/pgtool	Tue May 06 18:37:41 2014 +0200
+++ b/pgtool	Tue May 06 18:37:43 2014 +0200
@@ -24,21 +24,35 @@
 from importlib import import_module
 
 
-if len(sys.argv) < 2:
-    print(__doc__, end='')
-    sys.exit()
+def print_tool_with_short_desc(name):
+    module = import_module('pgtoolkit.tools.' + tool)
+    short_desc = module.cls.__doc__.lstrip().splitlines()[0]
+    print(name.ljust(15), '-', short_desc)
 
-if sys.argv[1] == '--list':
-    for tool in pgtoolkit.tools.__all__:
-        print(tool)
-    sys.exit()
+
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        print(__doc__, end='')
+        sys.exit()
 
-tool = sys.argv[1]
-tool_args = sys.argv[2:]
+    if sys.argv[1].startswith('--'):
+        if sys.argv[1] == '--list':
+            for tool in pgtoolkit.tools.__all__:
+                print_tool_with_short_desc(tool)
+        else:
+            print(__doc__, end='')
+        sys.exit()
 
-module = import_module('pgtoolkit.tools.' + tool)
+    tool = sys.argv[1]
+    tool_args = sys.argv[2:]
 
-tool = module.cls()
-tool.init(tool_args)
-tool.main()
+    if tool not in pgtoolkit.tools.__all__:
+        print('Unknown tool "%s".\n\nCall "pgtool --list" to get list of all available tools.' % tool)
+        sys.exit()
 
+    module = import_module('pgtoolkit.tools.' + tool)
+
+    tool = module.cls()
+    tool.setup(tool_args)
+    tool.main()
+