From 3723e611fc55f0d79e6574d3ae9646e7892244da Mon Sep 17 00:00:00 2001 From: pavelxdd Date: Fri, 8 Dec 2017 17:58:41 +0300 Subject: options: don't report errors on help value for OPT_CHOICE 'help' is a valid value for a lot of mpv options, such as `hwdec` or `vo` for printing available values, so this change makes the output of OPT_CHOICE options like `--video-sync=help` more consistent by not reporting an error about invalid value 'help'. --- options/m_option.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'options') diff --git a/options/m_option.c b/options/m_option.c index 2cb7a8aba5..9577c48577 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -441,6 +441,15 @@ const char *m_opt_choice_str(const struct m_opt_choice_alternatives *choices, return NULL; } +static void print_choice_values(struct mp_log *log, const struct m_option *opt) +{ + struct m_opt_choice_alternatives *alt = opt->priv; + for ( ; alt->name; alt++) + mp_info(log, " %s\n", alt->name[0] ? alt->name : "(passing nothing)"); + if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) + mp_info(log, " %g-%g (integer range)\n", opt->min, opt->max); +} + static int parse_choice(struct mp_log *log, const struct m_option *opt, struct bstr name, struct bstr param, void *dst) { @@ -457,6 +466,11 @@ static int parse_choice(struct mp_log *log, const struct m_option *opt, } } if (!alt->name) { + if (!bstrcmp0(param, "help")) { + mp_info(log, "Valid values for option %.*s are:\n", BSTR_P(name)); + print_choice_values(log, opt); + return M_OPT_EXIT; + } if (param.len == 0) return M_OPT_MISSING_PARAM; if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) { @@ -470,10 +484,7 @@ static int parse_choice(struct mp_log *log, const struct m_option *opt, mp_fatal(log, "Invalid value for option %.*s: %.*s\n", BSTR_P(name), BSTR_P(param)); mp_info(log, "Valid values are:\n"); - for (alt = opt->priv; alt->name; alt++) - mp_info(log, " %s\n", alt->name[0] ? alt->name : "(passing nothing)"); - if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) - mp_info(log, " %g-%g (integer range)\n", opt->min, opt->max); + print_choice_values(log, opt); return M_OPT_INVALID; } if (dst) -- cgit v1.2.3