#NEWLINE# @ autokwoargs #NEWLINE# def run( args = None , catch = ( ) , exit = True , out = None , err = None , * fn , **kwargs ) : #NEWLINE# #INDENT# "Runs a function or :ref:`CLI object<cli-object>` with ``args``, prints\n    the return value if not None, or catches the given exception types as well\n    as `clize.UserError` and prints their string representation, then exit with\n    the appropriate status code.\n\n    :param sequence args: The arguments to pass the CLI, for instance\n        ``('./a_script.py', 'spam', 'ham')``. If unspecified, uses `sys.argv`.\n    :param catch: Catch these exceptions and print their string representation\n        rather than letting Python print an uncaught exception traceback.\n    :type catch: sequence of exception classes\n    :param bool exit: If true, exit with the appropriate status code once the\n        function is done.\n    :param file out: The file in which to print the return value of the\n        command. If unspecified, uses `sys.stdout`\n    :param file err: The file in which to print any exception text.\n        If unspecified, uses `sys.stderr`.\n\n    " #NEWLINE# if ( len ( fn ) == 1 ) : #NEWLINE# #INDENT# fn = fn [ 0 ] #NEWLINE# #UNINDENT# cli = Clize . get_cli ( fn , ** kwargs ) #NEWLINE# if ( args is None ) : #NEWLINE# #INDENT# module = sys . modules [ '__main__' ] #NEWLINE# args = fix_argv ( sys . argv , sys . path , module ) #NEWLINE# #UNINDENT# if ( out is None ) : #NEWLINE# #INDENT# out = sys . stdout #NEWLINE# #UNINDENT# if ( err is None ) : #NEWLINE# #INDENT# err = sys . stderr #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ret = cli ( * args ) #NEWLINE# #UNINDENT# except ( tuple ( catch ) + ( errors . UserError , ) ) as exc : #NEWLINE# #INDENT# print ( str ( exc ) , file = err ) #NEWLINE# if exit : #NEWLINE# #INDENT# sys . exit ( ( 2 if isinstance ( exc , errors . ArgumentError ) else 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ret is not None ) : #NEWLINE# #INDENT# print ( ret , file = out ) #NEWLINE# #UNINDENT# if exit : #NEWLINE# #INDENT# sys . exit ( )