#NEWLINE# def cmd_parser( description , version ) : #NEWLINE# #INDENT# 'Create command line argument parser with common PostgreSQL options\n\n    :param description: text to display before the argument help\n    :param version: version of the caller\n    :return: the created parser\n    ' #NEWLINE# global _cfg #NEWLINE# parent = ArgumentParser ( add_help = False ) #NEWLINE# parent . add_argument ( 'dbname' , help = 'database name' ) #NEWLINE# group = parent . add_argument_group ( 'Connection options' ) #NEWLINE# if ( _cfg is None ) : #NEWLINE# #INDENT# _cfg = Config ( ) #NEWLINE# #UNINDENT# dbcfg = ( _cfg [ 'database' ] if ( 'database' in _cfg ) else { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# group . add_argument ( '-H' , '--host' , ** _help_dflt ( 'host' , dbcfg ) ) #NEWLINE# group . add_argument ( '-p' , '--port' , type = int , ** _help_dflt ( 'port' , dbcfg ) ) #NEWLINE# group . add_argument ( '-U' , '--username' , ** _help_dflt ( 'username' , dbcfg ) ) #NEWLINE# group . add_argument ( '-W' , '--password' , action = 'store_true' , help = 'force password prompt' ) #NEWLINE# parent . add_argument ( '-c' , '--config' , type = FileType ( 'r' ) , help = 'configuration file path' ) #NEWLINE# parent . add_argument ( '-r' , '--repository' , default = _repo_path ( _cfg ) , help = 'root of repository (default %(default)s)' ) #NEWLINE# parent . add_argument ( '-o' , '--output' , type = FileType ( 'w' ) , help = 'output file name (default stdout)' ) #NEWLINE# parser = ArgumentParser ( parents = [ parent ] , description = description ) #NEWLINE# parser . add_argument ( '--version' , action = 'version' , version = ( '%(prog)s ' + ( '%s' % version ) ) ) #NEWLINE# return parser