#NEWLINE# def build_command_line_parser( d , parser = None , prefix = '' , **parser_args ) : #NEWLINE# #INDENT# def camel_to_dashes( s ) : #NEWLINE# #INDENT# s1 = re . sub ( '(.)([A-Z][a-z]+)' , '\\1-\\2' , s ) #NEWLINE# return re . sub ( '([a-z0-9])([A-Z])' , '\\1-\\2' , s1 ) . lower ( ) #NEWLINE# #UNINDENT# if ( parser is None ) : #NEWLINE# #INDENT# parser = argparse . ArgumentParser ( prog = 'vistrails' , ** parser_args ) #NEWLINE# parser . _my_arg_groups = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# parser . add_argument ( 'vistrails' , metavar = 'vistrail' , type = str , nargs = '*' , help = 'Vistrail to open' ) #NEWLINE# _usage_args . add ( 'vistrails' ) #NEWLINE# parser . add_argument ( '--version' , action = RawVersionAction , version = system . about_string ( ) ) #NEWLINE# #UNINDENT# prefix_dashes = '' #NEWLINE# if prefix : #NEWLINE# #INDENT# prefix_dashes = camel_to_dashes ( prefix . replace ( '.' , '-' ) ) #NEWLINE# #UNINDENT# for ( category , fields ) in d . iteritems ( ) : #NEWLINE# #INDENT# if ( category == 'Internal' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( category == 'Command-Line' ) : #NEWLINE# #INDENT# cat_group = parser #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( category not in parser . _my_arg_groups ) : #NEWLINE# #INDENT# parser . _my_arg_groups [ category ] = parser . add_argument_group ( category ) #NEWLINE# #UNINDENT# cat_group = parser . _my_arg_groups [ category ] #NEWLINE# #UNINDENT# for field in fields : #NEWLINE# #INDENT# if isinstance ( field , ConfigFieldParent ) : #NEWLINE# #INDENT# build_command_line_parser ( { #NEWLINE# #INDENT# category : field . sub_fields , #NEWLINE# #UNINDENT# } , parser , ( '%s%s.' % ( prefix , field . name ) ) , ** parser_args ) #NEWLINE# continue #NEWLINE# #UNINDENT# k_dashes = camel_to_dashes ( field . name ) #NEWLINE# help_str = find_help ( ( '%s%s' % ( prefix , field . name ) ) ) #NEWLINE# dest_name = ( prefix + field . name ) #NEWLINE# config_type = field . field_type #NEWLINE# if ( config_type is None ) : #NEWLINE# #INDENT# config_type = ConfigType . NORMAL #NEWLINE# #UNINDENT# if ( ( config_type == ConfigType . INTERNAL ) or ( config_type == ConfigType . STORAGE ) or ( config_type == ConfigType . INTERNAL_SUBOBJECT ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( config_type == ConfigType . ON_OFF ) : #NEWLINE# #INDENT# k_dashes = camel_to_dashes ( field . name ) #NEWLINE# group = cat_group . add_mutually_exclusive_group ( ) #NEWLINE# group . add_argument ( ( '--%s%s' % ( prefix_dashes , k_dashes ) ) , action = nested_action ( group , 'store_true' ) , dest = dest_name , help = help_str , default = argparse . SUPPRESS ) #NEWLINE# group . add_argument ( ( '--no-%s%s' % ( prefix_dashes , k_dashes ) ) , action = nested_action ( group , 'store_false' ) , dest = dest_name , help = ( 'Inverse of --%s%s' % ( prefix_dashes , k_dashes ) ) , default = argparse . SUPPRESS ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( config_type == ConfigType . SHOW_HIDE ) : #NEWLINE# #INDENT# k_dashes = camel_to_dashes ( field . name [ 4 : ] ) #NEWLINE# group = cat_group . add_mutually_exclusive_group ( ) #NEWLINE# group . add_argument ( ( '--show-%s%s' % ( prefix_dashes , k_dashes ) ) , action = nested_action ( group , 'store_true' ) , dest = dest_name , help = help_str , default = argparse . SUPPRESS ) #NEWLINE# group . add_argument ( ( '--hide-%s%s' % ( prefix_dashes , k_dashes ) ) , action = nested_action ( group , 'store_false' ) , dest = dest_name , help = ( 'Inverse of --show-%s%s' % ( prefix_dashes , k_dashes ) ) , default = argparse . SUPPRESS ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# k_dashes = camel_to_dashes ( field . name ) #NEWLINE# long_arg = ( '--%s%s' % ( prefix_dashes , k_dashes ) ) #NEWLINE# if ( kwargs . flag is not None ) : #NEWLINE# #INDENT# args = ( field . flag , long_arg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# args = ( long_arg , ) #NEWLINE# #UNINDENT# kwargs = { #NEWLINE# #INDENT# 'dest' : dest_name , #NEWLINE# 'help' : help_str , #NEWLINE# 'default' : argparse . SUPPRESS , #NEWLINE# #UNINDENT# } #NEWLINE# if ( ( field . val_type != ConfigPath ) and ( field . val_type != ConfigURL ) and ( field . val_type != str ) and ( field . val_type != bool ) ) : #NEWLINE# #INDENT# kwargs [ 'type' ] = field . val_type #NEWLINE# #UNINDENT# if ( config_type == ConfigType . SUBOBJECT ) : #NEWLINE# #INDENT# kwargs [ 'action' ] = NestedSetKwargs #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( config_type == ConfigType . COMMAND_LINE_FLAG ) : #NEWLINE# #INDENT# kwargs [ 'action' ] = nested_action ( cat_group , 'store_true' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kwargs [ 'action' ] = nested_action ( cat_group , 'store' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( field . val_type == ConfigPath ) : #NEWLINE# #INDENT# kwargs [ 'metavar' ] = 'DIR' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field . val_type == ConfigURL ) : #NEWLINE# #INDENT# kwargs [ 'metavar' ] = 'URL' #NEWLINE# #UNINDENT# #UNINDENT# if ( field . nargs is not None ) : #NEWLINE# #INDENT# kwargs [ 'nargs' ] = field . nargs #NEWLINE# #UNINDENT# cat_group . add_argument ( * args , ** kwargs ) #NEWLINE# if ( category == 'Command-Line' ) : #NEWLINE# #INDENT# _usage_args . add ( field . name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return parser