def parse_and_validate_commands(args=sys.argv[1:]):
    # Find local fabfile path or abort
    fabfile = "prestoadmin"

    # Store absolute path to fabfile in case anyone needs it
    state.env.real_fabfile = fabfile

    # Load fabfile (which calls its module-level code, including
    # tweaks to env values) and put its commands in the shared commands
    # dict
    docstring, callables = load_fabfile(fabfile)
    state.commands.update(callables)

    # Parse command line options
    parser = parser_for_options()

    # Unless you pass in values, optparse fills in the default values for all
    # of the options. We want to save the version of the options without
    # default values, because that takes precedence over all other env vars.
    non_default_options, arguments = parser.parse_args(args, values=Values())
    options, arguments = parser.parse_args(args)
    default_options = get_default_options(options, non_default_options)

    # Handle regular args vs -- args
    arguments = parser.largs

    if len(parser.rargs) > 0:
        warn("Arbitrary remote shell commands not supported.")
        show_commands(None, 'normal', 2)

    if options.extended_help:
        parser.print_extended_help()
        sys.exit(0)

    # If user didn't specify any commands to run, show help
    if not arguments:
        parser.print_help()
        sys.exit(0)  # don't consider this an error

    # Parse arguments into commands to run (plus args/kwargs/hosts)
    commands_to_run = None
    try:
        commands_to_run = parse_arguments(arguments, state.commands)
    except __HOLE__ as e:
        warn(e.message)
        _LOGGER.warn("Unable to parse arguments", exc_info=True)
        parser.print_help()
        sys.exit(2)

    # Handle show (command-specific help) option
    if options.display:
        display_command(commands_to_run[0][0])

    load_config_callback = _get_config_callback(commands_to_run)
    _update_env(default_options, non_default_options, load_config_callback)

    if not options.serial:
        state.env.parallel = True

    state.env.warn_only = False

    # Initial password prompt, if requested
    if options.initial_password_prompt:
        prompt = "Initial value for env.password: "
        state.env.password = getpass.getpass(prompt)

    state.env['tasks'] = [x[0] for x in commands_to_run]

    return commands_to_run
dataset/ETHPy150Open prestodb/presto-admin/prestoadmin/main.py/parse_and_validate_commands