#NEWLINE# def main( argv = None ) : #NEWLINE# #INDENT# import lymph.monkey #NEWLINE# lymph . monkey . patch ( ) #NEWLINE# import docopt #NEWLINE# import sys #NEWLINE# import logging #NEWLINE# from lymph import __version__ as VERSION #NEWLINE# from lymph.cli.help import HELP #NEWLINE# from lymph.cli.base import get_command_class #NEWLINE# from lymph.utils import logging as lymph_logging #NEWLINE# bootup_handler = logging . StreamHandler ( ) #NEWLINE# logging . getLogger ( ) . addHandler ( bootup_handler ) #NEWLINE# args = docopt . docopt ( HELP , argv , version = VERSION , options_first = True ) #NEWLINE# name = args . pop ( '<command>' ) #NEWLINE# argv = args . pop ( '<args>' ) #NEWLINE# try : #NEWLINE# #INDENT# command_cls = get_command_class ( name ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# print ( ( "'%s' is not a valid lymph command. See 'lymph list' or 'lymph help'." % name ) ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# command_args = docopt . docopt ( command_cls . get_help ( ) , ( [ name ] + argv ) ) #NEWLINE# args . update ( command_args ) #NEWLINE# config = ( setup_config ( args ) if command_cls . needs_config else None ) #NEWLINE# logging . getLogger ( ) . removeHandler ( bootup_handler ) #NEWLINE# if config : #NEWLINE# #INDENT# loglevel = args . get ( '--loglevel' , 'ERROR' ) #NEWLINE# logfile = args . get ( '--logfile' ) #NEWLINE# lymph_logging . setup_logging ( config , config , logfile ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logging . basicConfig ( ) #NEWLINE# #UNINDENT# sys . excepthook = _excepthook #NEWLINE# terminal = setup_terminal ( args , config ) #NEWLINE# command = command_cls ( args , config , terminal ) #NEWLINE# return command . run ( )