<s> from __future__ import unicode_literals <EOL> class CommandOption ( object ) : <EOL> """<STR_LIT>""" <EOL> choices = None <EOL> OPTION_VALUES = range ( <NUM_LIT> ) <EOL> TYPE_FILEPATH , TYPE_DIRPATH , TYPE_BOOLEAN , TYPE_NUMERIC , TYPE_CONTAINER , TYPE_CONTAINER_RUN , TYPE_IMAGE , TYPE_IMAGE_TAGGED , TYPE_IMAGE_TAG , TYPE_COMMAND , TYPE_COMMAND_ARG , TYPE_CHOICE , TYPE_KEYVALUE , TYPE_PORT_BINDING , TYPE_PORT_RANGE , TYPE_OBJECT , TYPE_STRING , TYPE_VOLUME = OPTION_VALUES <EOL> def __init__ ( self , option_type , short_name , long_name = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if option_type not in self . OPTION_VALUES : <EOL> raise ValueError ( "<STR_LIT>" , option_type ) <EOL> if long_name and short_name : <EOL> arguments = [ short_name , long_name ] <EOL> self . display = '<STR_LIT>' . format ( short_name , long_name ) <EOL> elif long_name : <EOL> arguments = [ long_name ] <EOL> self . display = long_name <EOL> else : <EOL> arguments = [ short_name ] <EOL> self . display = short_name <EOL> if '<STR_LIT>' in kwargs and kwargs [ '<STR_LIT>' ] is not None : <EOL> self . api_match = kwargs [ '<STR_LIT>' ] <EOL> del kwargs [ '<STR_LIT>' ] <EOL> else : <EOL> self . api_match = True <EOL> if '<STR_LIT>' in kwargs and kwargs [ '<STR_LIT>' ] is not None : <EOL> self . cli_match = kwargs [ '<STR_LIT>' ] <EOL> del kwargs [ '<STR_LIT>' ] <EOL> else : <EOL> self . cli_match = True <EOL> if '<STR_LIT>' in kwargs : <EOL> self . dest = kwargs [ '<STR_LIT>' ] <EOL> elif long_name : <EOL> self . dest = long_name . strip ( '<STR_LIT:->' ) <EOL> else : <EOL> self . dest = short_name . strip ( '<STR_LIT:->' ) <EOL> self . default = kwargs [ '<STR_LIT:default>' ] if '<STR_LIT:default>' in kwargs else None <EOL> if '<STR_LIT>' in kwargs : <EOL> self . is_optional = ( kwargs [ '<STR_LIT>' ] in [ '<STR_LIT:?>' , '<STR_LIT:*>' ] ) <EOL> self . is_multiple = ( kwargs [ '<STR_LIT>' ] in [ '<STR_LIT:+>' , '<STR_LIT:*>' ] ) <EOL> if kwargs [ '<STR_LIT>' ] in [ '<STR_LIT:?>' , '<STR_LIT:*>' , '<STR_LIT:+>' ] : <EOL> if kwargs [ '<STR_LIT>' ] in [ '<STR_LIT:*>' , '<STR_LIT:+>' ] : <EOL> kwargs [ '<STR_LIT:action>' ] = '<STR_LIT>' <EOL> del kwargs [ '<STR_LIT>' ] <EOL> else : <EOL> self . is_optional = False <EOL> self . is_multiple = False <EOL> if '<STR_LIT>' in kwargs : <EOL> self . choices = kwargs [ '<STR_LIT>' ] <EOL> if option_type != CommandOption . TYPE_CHOICE : <EOL> kwargs . pop ( '<STR_LIT>' ) <EOL> self . option_type = option_type <EOL> self . short_name = short_name <EOL> self . long_name = long_name <EOL> self . args = arguments <EOL> self . kwargs = kwargs <EOL> def is_type_choice ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_CHOICE or self . choices <EOL> def is_type_container ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_CONTAINER <EOL> def is_type_running ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_CONTAINER_RUN <EOL> def is_type_image ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_IMAGE <EOL> def is_type_tagged ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_IMAGE_TAGGED <EOL> def is_type_volume ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_VOLUME <EOL> def is_type_filepath ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_FILEPATH <EOL> def is_type_dirname ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . option_type == CommandOption . TYPE_DIRPATH <EOL> def get_name ( self , is_long ) : <EOL> """<STR_LIT>""" <EOL> if is_long : <EOL> return self . long_name if self . long_name else self . short_name <EOL> return self . short_name if self . short_name else self . long_name <EOL> def is_match ( self , word ) : <EOL> """<STR_LIT>""" <EOL> if word : <EOL> return ( self . long_name and self . long_name . startswith ( word ) ) or ( self . short_name and self . short_name . startswith ( word ) ) <EOL> return True <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . long_name if self . long_name else self . short_name <EOL> @ property <EOL> def names ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . short_name and self . long_name : <EOL> return [ self . short_name , self . long_name ] <EOL> elif self . long_name : <EOL> return [ self . long_name ] <EOL> else : <EOL> return [ self . short_name ] <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' . format ( <EOL> self . short_name , <EOL> self . long_name ) </s>
