def command_dispatch(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    # Assume the first arg after the option is the command to run
    for icmd, cmd in enumerate(argv):
        if not cmd.startswith('-'):
            argv = [_get_exec(cmd)] + argv[:icmd] + argv[icmd+1:]
            break
    else:
        # No command specified: dispatch to the pgxnclient script
        # to print basic help, main command etc.
        argv = ([os.path.join(os.path.dirname(sys.argv[0]), 'pgxnclient')]
            + argv)

    if not os.access(argv[0], os.X_OK):
        # This is our friend setuptools' job: the script have lost the
        # executable flag. We assume the script is a Python one and run it
        # through the current executable.
        argv.insert(0, sys.executable)

    os.execv(argv[0], argv)
Entry point for a script to dispatch commands to external scripts.
dataset/ETHPy150Open dvarrazzo/pgxnclient/pgxnclient/cli.py/command_dispatch