mirror of
https://github.com/mpv-player/mpv
synced 2024-08-20 08:55:06 +02:00
m_config: introduce and use OPT_ALIAS for some options
OPT_ALIAS redirects the options at a higher level, instead of introducing "duplicate" options with different name but same backing storage. This uses the OPT_REPLACED mechanisms - only the deprecation warning had to be made conditional. Note that e.g. --no-video still works, because the "--no-..." redirection and OPT_ALIAS are orthogonal. The deprecated --sub -> --sub-file alias had to be dropped, because it essentially conflicts with --no-sub. If anyone complains, this could probably still be undone by letting m_config_find_negation_opt do a special mapping for --no-sub. (Which would be dumb, but simple and effective.)
This commit is contained in:
parent
e024906408
commit
7dde096d8a
@ -362,6 +362,9 @@ static void m_config_add_option(struct m_config *config,
|
||||
co.name = talloc_asprintf(config, "%s-%s", parent_name, co.name);
|
||||
}
|
||||
|
||||
if (co.opt->deprecation_message)
|
||||
co.is_hidden = true;
|
||||
|
||||
// Option with children -> add them
|
||||
if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
|
||||
const struct m_sub_options *subopts = arg->priv;
|
||||
@ -395,7 +398,6 @@ static void m_config_add_option(struct m_config *config,
|
||||
MP_TARRAY_APPEND(config, config->opts, config->num_opts, co);
|
||||
|
||||
if (co.opt->type == &m_option_type_alias) {
|
||||
co.is_hidden = true;
|
||||
const char *alias = (const char *)co.opt->priv;
|
||||
char no_alias[40];
|
||||
snprintf(no_alias, sizeof(no_alias), "no-%s", alias);
|
||||
@ -408,9 +410,6 @@ static void m_config_add_option(struct m_config *config,
|
||||
m_config_add_option(config, NULL, NULL, NULL, new);
|
||||
}
|
||||
}
|
||||
|
||||
if (co.opt->type == &m_option_type_removed)
|
||||
co.is_hidden = true;
|
||||
}
|
||||
|
||||
struct m_config_option *m_config_get_co(const struct m_config *config,
|
||||
@ -434,7 +433,9 @@ struct m_config_option *m_config_get_co(const struct m_config *config,
|
||||
const char *prefix = config->is_toplevel ? "--" : "";
|
||||
if (co->opt->type == &m_option_type_alias) {
|
||||
const char *alias = (const char *)co->opt->priv;
|
||||
if (!co->warning_was_printed) {
|
||||
// deprecation_message is not used, but decides whether it's a
|
||||
// proper or deprecated alias.
|
||||
if (co->opt->deprecation_message && !co->warning_was_printed) {
|
||||
MP_WARN(config, "Warning: option %s%s was replaced with "
|
||||
"%s%s and might be removed in the future.\n",
|
||||
prefix, co->name, prefix, alias);
|
||||
@ -788,9 +789,6 @@ void m_config_print_option_list(const struct m_config *config)
|
||||
continue;
|
||||
if (co->is_hidden)
|
||||
continue;
|
||||
if (opt->type == &m_option_type_alias ||
|
||||
opt->type == &m_option_type_removed)
|
||||
continue;
|
||||
MP_INFO(config, " %s%-30s", prefix, co->name);
|
||||
if (opt->type == &m_option_type_choice) {
|
||||
MP_INFO(config, " Choices:");
|
||||
|
@ -691,13 +691,20 @@ extern const char m_option_path_separator;
|
||||
.type = &m_option_type_subconfig, \
|
||||
.priv = (void*)&subconf)
|
||||
|
||||
// If "--name" was removed, but "--newname" has the same semantics.
|
||||
// Provide a another name for the option.
|
||||
#define OPT_ALIAS(optname, newname) \
|
||||
{.name = optname, .type = &m_option_type_alias, .priv = newname, \
|
||||
.offset = -1}
|
||||
|
||||
// If "--optname" was removed, but "--newname" has the same semantics.
|
||||
// It will be redirected, and a warning will be printed on first use.
|
||||
#define OPT_REPLACED(optname, newname) \
|
||||
{.name = optname, .type = &m_option_type_alias, .priv = newname, .offset = -1}
|
||||
{.name = optname, .type = &m_option_type_alias, .priv = newname, \
|
||||
.deprecation_message = "", .offset = -1}
|
||||
|
||||
// "--name" doesn't exist, but inform the user about a replacement with msg.
|
||||
// "--optname" doesn't exist, but inform the user about a replacement with msg.
|
||||
#define OPT_REMOVED(optname, msg) \
|
||||
{.name = optname, .type = &m_option_type_removed, .priv = msg, .offset = -1}
|
||||
{.name = optname, .type = &m_option_type_removed, .priv = msg, \
|
||||
.deprecation_message = "", .offset = -1}
|
||||
|
||||
#endif /* MPLAYER_M_OPTION_H */
|
||||
|
@ -119,7 +119,7 @@ static const m_option_t mp_vo_opt_list[] = {
|
||||
OPT_FLOATRANGE("monitoraspect", force_monitor_aspect, 0, 0.0, 9.0),
|
||||
OPT_FLOATRANGE("monitorpixelaspect", monitor_pixel_aspect, 0, 0.2, 9.0),
|
||||
OPT_FLAG("fullscreen", fullscreen, M_OPT_FIXED),
|
||||
OPT_FLAG("fs", fullscreen, M_OPT_FIXED),
|
||||
OPT_ALIAS("fs", "fullscreen"),
|
||||
OPT_FLAG("native-keyrepeat", native_keyrepeat, M_OPT_FIXED),
|
||||
OPT_FLOATRANGE("panscan", panscan, 0, 0.0, 1.0),
|
||||
OPT_FLOATRANGE("video-zoom", zoom, 0, -20.0, 20.0),
|
||||
@ -303,9 +303,9 @@ const m_option_t mp_opts[] = {
|
||||
OPT_TRACKCHOICE("ff-aid", stream_id_ff[STREAM_AUDIO]),
|
||||
OPT_TRACKCHOICE("ff-vid", stream_id_ff[STREAM_VIDEO]),
|
||||
OPT_TRACKCHOICE("ff-sid", stream_id_ff[STREAM_SUB]),
|
||||
OPT_FLAG_STORE("no-sub", stream_id[0][STREAM_SUB], 0, -2),
|
||||
OPT_FLAG_STORE("no-video", stream_id[0][STREAM_VIDEO], 0, -2),
|
||||
OPT_FLAG_STORE("no-audio", stream_id[0][STREAM_AUDIO], 0, -2),
|
||||
OPT_ALIAS("sub", "sid"),
|
||||
OPT_ALIAS("video", "vid"),
|
||||
OPT_ALIAS("audio", "aid"),
|
||||
OPT_STRINGLIST("alang", stream_lang[STREAM_AUDIO], 0),
|
||||
OPT_STRINGLIST("slang", stream_lang[STREAM_SUB], 0),
|
||||
|
||||
@ -689,7 +689,6 @@ const m_option_t mp_opts[] = {
|
||||
OPT_REPLACED("ss", "start"),
|
||||
OPT_REPLACED("stop-xscreensaver", "stop-screensaver"),
|
||||
OPT_REPLACED("sub-fuzziness", "sub-auto"),
|
||||
OPT_REPLACED("sub", "sub-file"),
|
||||
OPT_REPLACED("subcp", "sub-codepage"),
|
||||
OPT_REPLACED("subdelay", "sub-delay"),
|
||||
OPT_REPLACED("subfile", "sub-file"),
|
||||
|
Loading…
Reference in New Issue
Block a user