diff options
author | pavelxdd <pavel.otchertsov@gmail.com> | 2017-12-08 17:58:41 +0300 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2017-12-08 20:47:14 +0200 |
commit | 3723e611fc55f0d79e6574d3ae9646e7892244da (patch) | |
tree | 30f610096a90d83410df3fb6285ec21713bf2ab8 | |
parent | 0a749a38f7c5229025efd88318d83767c1458d55 (diff) | |
download | mpv-3723e611fc55f0d79e6574d3ae9646e7892244da.tar.bz2 mpv-3723e611fc55f0d79e6574d3ae9646e7892244da.tar.xz |
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'.
-rw-r--r-- | options/m_option.c | 19 |
1 files changed, 15 insertions, 4 deletions
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) |