<s> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> from swiftly . cli . optionparser import OptionParser <EOL> class ReturnCode ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text = None , code = <NUM_LIT:1> ) : <EOL> Exception . __init__ ( self , text ) <EOL> self . text = text <EOL> self . code = code <EOL> class CLICommand ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cli , name , min_args = None , max_args = None , usage = None ) : <EOL> self . cli = cli <EOL> self . name = name <EOL> self . min_args = min_args <EOL> self . max_args = max_args <EOL> if usage is None : <EOL> usage = """<STR_LIT>""" . strip ( ) % ( name , name ) <EOL> self . option_parser = OptionParser ( <EOL> usage = usage , io_manager = self . cli . context . io_manager , <EOL> error_prefix = name + '<STR_LIT>' ) <EOL> def parse_args_and_create_context ( self , args ) : <EOL> """<STR_LIT>""" <EOL> original_args = args <EOL> try : <EOL> options , args = self . option_parser . parse_args ( args ) <EOL> except UnboundLocalError : <EOL> pass <EOL> if self . option_parser . error_encountered : <EOL> if '<STR_LIT>' in original_args or '<STR_LIT>' in original_args or '<STR_LIT>' in original_args : <EOL> self . option_parser . print_help ( ) <EOL> raise ReturnCode ( ) <EOL> if options . help : <EOL> self . option_parser . print_help ( ) <EOL> raise ReturnCode ( ) <EOL> if self . min_args is not None and len ( args ) < self . min_args : <EOL> raise ReturnCode ( <EOL> '<STR_LIT>' % self . min_args ) <EOL> if self . max_args is not None and len ( args ) > self . max_args : <EOL> raise ReturnCode ( <EOL> '<STR_LIT>' % self . max_args ) <EOL> context = self . cli . context . copy ( ) <EOL> context . muted_account_headers = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:date>' ] <EOL> context . muted_container_headers = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:date>' ] <EOL> context . muted_object_headers = [ '<STR_LIT>' , '<STR_LIT:date>' ] <EOL> return options , args , context <EOL> def options_list_to_lowered_dict ( self , options_list ) : <EOL> """<STR_LIT>""" <EOL> result = { } <EOL> if options_list : <EOL> for key in options_list : <EOL> key = key . lstrip ( ) <EOL> colon = key . find ( '<STR_LIT::>' ) <EOL> if colon < <NUM_LIT:1> : <EOL> colon = None <EOL> equal = key . find ( '<STR_LIT:=>' ) <EOL> if equal < <NUM_LIT:1> : <EOL> equal = None <EOL> if colon and ( not equal or colon < equal ) : <EOL> key , value = key . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> elif equal : <EOL> key , value = key . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> else : <EOL> value = '<STR_LIT>' <EOL> result [ key . lower ( ) ] = value . lstrip ( ) <EOL> return result </s>
