mirror of
https://github.com/mpv-player/mpv
synced 2025-03-19 01:47:38 +00: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:
parent
4f7abd5e43
commit
38b05daf7d
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user