0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

parse_commandline: fail gracefully on bad args

Args of zero length (i.e. --=) now display a proper error message.

Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
wd0 2015-03-29 03:03:34 -04:00 committed by wm4
parent 4f7abd5e43
commit 38b05daf7d
2 changed files with 6 additions and 3 deletions

View File

@ -61,7 +61,7 @@ char *m_option_strerror(int code)
case M_OPT_MISSING_PARAM:
return "option requires parameter";
case M_OPT_INVALID:
return "option parameter could not be parsed";
return "option could not be parsed";
case M_OPT_OUT_OF_RANGE:
return "parameter is outside values allowed for option";
case M_OPT_DISALLOW_PARAM:

View File

@ -80,6 +80,9 @@ static int split_opt_silent(struct parse_state *p)
bool ambiguous = !bstr_split_tok(p->arg, "=", &p->arg, &p->param);
if (!p->arg.len)
return M_OPT_INVALID;
bool need_param = m_config_option_requires_param(p->config, p->arg) > 0;
if (ambiguous && need_param) {
@ -100,7 +103,7 @@ static bool split_opt(struct parse_state *p)
return r == 0;
p->error = true;
MP_FATAL(p->config, "Error parsing commandline option %.*s: %s\n",
MP_FATAL(p->config, "Error parsing command line option '%.*s': %s\n",
BSTR_P(p->arg), m_option_strerror(r));
return false;
}
@ -154,7 +157,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
goto err_out;
}
if (r < 0) {
MP_FATAL(config, "Setting commandline option --%.*s=%.*s failed.\n",
MP_FATAL(config, "Setting command line option '--%.*s=%.*s' failed.\n",
BSTR_P(p.arg), BSTR_P(p.param));
goto err_out;
}