Runs the program with an optional 'main' function and 'argv' list.

def run(main=None, argv=None):
    """Runs the program with an optional 'main' function and 'argv' list."""

    # Define help flags.
    _define_help_flags()

    # Parse known flags.
    argv = flags.FLAGS(_sys.argv if argv is None else argv, known_only=True)

    main = main or _sys.modules['__main__'].main

    # Call the main function, passing through any arguments
    # to the final program.
    _sys.exit(main(argv))