pgtool
changeset 100 d6088dba8fea
child 101 2a2d0d5df03b
equal deleted inserted replaced
99:245646538743 100:d6088dba8fea
       
     1 #!/usr/bin/env python3
       
     2 
       
     3 """
       
     4 Wrapper script for pgtoolkit tools.
       
     5 
       
     6 Usage:
       
     7 
       
     8     pgtool --list
       
     9         List all available tools.
       
    10 
       
    11     pgtool <tool_name> <arg_1> <arg_2> ...
       
    12         Run tool. All args except first one are forwarded to the tool.
       
    13 
       
    14     pgtool schemadiff db1 db2
       
    15         E.g. run schemadiff between db1 and db2.
       
    16 
       
    17     pgtool schemadiff --help
       
    18         Get help for tool parameters.
       
    19 
       
    20 """
       
    21 
       
    22 import pgtoolkit.tools
       
    23 import sys
       
    24 from importlib import import_module
       
    25 
       
    26 
       
    27 if len(sys.argv) < 2:
       
    28     print(__doc__, end='')
       
    29     sys.exit()
       
    30 
       
    31 if sys.argv[1] == '--list':
       
    32     for tool in pgtoolkit.tools.__all__:
       
    33         print(tool)
       
    34     sys.exit()
       
    35 
       
    36 tool = sys.argv[1]
       
    37 tool_args = sys.argv[2:]
       
    38 
       
    39 module = import_module('pgtoolkit.tools.' + tool)
       
    40 
       
    41 tool = module.cls()
       
    42 tool.init(tool_args)
       
    43 tool.main()
       
    44