def run(main=None, argv=None, **flags):
"""<STR_LIT>"""<EOL>import sys as _sys<EOL>import inspect<EOL>main = main or _sys.modules['<STR_LIT:__main__>'].main<EOL>if main.__doc__:<EOL><INDENT>docstring = main.__doc__.split('<STR_LIT>')[<NUM_LIT:0>]<EOL>_parser.usage = '<STR_LIT>'.format(docstring)  <EOL><DEDENT>try:<EOL><INDENT>a = inspect.getfullargspec(main)<EOL><DEDENT>except AttributeError:<EOL><INDENT>a = inspect.getargspec(main)  <EOL><DEDENT>if a.defaults:<EOL><INDENT>kwargs = dict(zip(reversed(a.args), reversed(a.defaults)))<EOL>add_flag(**kwargs)<EOL><DEDENT>else:<EOL><INDENT>kwargs = dict()<EOL><DEDENT>if a.defaults is None:<EOL><INDENT>nargs = len(a.args)<EOL><DEDENT>else:<EOL><INDENT>nargs = len(a.args) - len(a.defaults)<EOL><DEDENT>posargs = a.args[:nargs]<EOL>flag.add_args(posargs)<EOL>add_flag(**flags)<EOL>args = argv[<NUM_LIT:1>:] if argv else None<EOL>unparsed, kw = flag._parse_flags_kw(args=args)<EOL>d = flag.__dict__['<STR_LIT>']<EOL>args = [d[k] for k in posargs]<EOL>args += unparsed<EOL>kwargs.update({k: d[k] for k in kwargs.keys()})<EOL>kwargs.update(kw)<EOL>_sys.exit(main(*args, **kwargs))<EOL>
:param main: main or sys.modules['__main__'].main
:param argv: argument list used in argument parse
:param flags: flags to define with defaults
:return: