def METHOD_NAME(command=None):
    global _hyphened_command
    sys.dont_write_bytecode = True
    # construct args list. Note that commands like 'rez-env foo' and
    # 'rez env foo' are equivalent
    #
    if command:
        # like 'rez-foo arg1 arg2'
        args = [command] + sys.argv[1:]
        _hyphened_command = True
    elif len(sys.argv) > 1 and sys.argv[1] in subcommands:
        # like 'rez foo arg1 arg2'
        command = sys.argv[1]
        args = sys.argv[1:]
    else:
        # like 'rez -i'
        args = sys.argv[1:]
    # parse args depending on subcommand behaviour
    if command:
        arg_mode = subcommands[command].get("arg_mode")
    else:
        arg_mode = None
    parser = setup_parser()
    if arg_mode == "grouped":
        # args split into groups by '--'
        arg_groups = [[]]
        for arg in args:
            if arg == '--':
                arg_groups.append([])
                continue
            arg_groups[-1].append(arg)
        opts = parser.parse_args(arg_groups[0])
        extra_arg_groups = arg_groups[1:]
    elif arg_mode == "passthrough":
        # unknown args passed in first extra_arg_group
        opts, extra_args = parser.parse_known_args(args)
        extra_arg_groups = [extra_args]
    else:
        # native arg parsing
        opts = parser.parse_args(args)
        extra_arg_groups = []
    if opts.debug or _env_var_true("REZ_DEBUG"):
        exc_type = _NeverError
    else:
        exc_type = RezError
    def run_cmd():
        try:
            # python3 will not automatically handle cases where no sub parser
            # has been selected. In these cases func will not exist, and an
            # AttributeError will be raised.
            func = opts.func
        except AttributeError:
            parser.error("too few arguments.")
        else:
            return func(opts, opts.parser, extra_arg_groups)
    if opts.profile:
        import cProfile
        cProfile.runctx("run_cmd()", globals(), locals(), filename=opts.profile)
        returncode = 0
    else:
        try:
            returncode = run_cmd()
        except (NotImplementedError, RezSystemError):
            raise
        except exc_type as e:
            print_error("%s: %s" % (e.__class__.__name__, str(e)))
            sys.exit(1)
    sys.exit(returncode or 0)