player/command: add default-value/choices arg fields to command-list

Add optional 'default-value' and 'choices' fields where appropriate
for command arguments in the 'command-list' property. Update
documentation to reflect the command-list schema change.

DOCS/interface-changes/command-list: add changes
This commit is contained in:
zenodity
2026-03-07 11:27:52 +00:00
committed by Kacper Michajłow
parent bed0f49729
commit ae2384bce0
3 changed files with 30 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
'command-list' now also returns a default value and available choices where applicable for each command argument.
+6 -3
View File
@@ -4209,9 +4209,12 @@ Property list
"vararg" MPV_FORMAT_FLAG
"args" MPV_FORMAT_NODE_ARRAY
MPV_FORMAT_NODE_MAP
"name" MPV_FORMAT_STRING
"type" MPV_FORMAT_STRING
"optional" MPV_FORMAT_FLAG
"name" MPV_FORMAT_STRING
"type" MPV_FORMAT_STRING
"optional" MPV_FORMAT_FLAG
"default-value" MPV_FORMAT_NODE (optional, value of "type")
"choices" MPV_FORMAT_NODE_ARRAY (optional)
MPV_FORMAT_STRING
``input-bindings``
The list of current input key bindings. This returns an array of maps,
+23
View File
@@ -4035,6 +4035,29 @@ static int mp_property_commands(void *ctx, struct m_property *prop,
node_map_add_string(ae, "name", a->name);
node_map_add_string(ae, "type", a->type->name);
node_map_add_flag(ae, "optional", a->flags & MP_CMD_OPT_ARG);
if (a->type == &m_option_type_choice ||
a->type == &m_option_type_flags) {
const struct m_opt_choice_alternatives *alt = a->priv;
if (alt) {
if (a->defval) {
const int ival = *(const int *)a->defval;
const char *val = m_opt_choice_str_def(alt, ival, NULL);
if (val)
node_map_add_string(ae, "default-value", val);
}
struct mpv_node *choices =
node_map_add(ae, "choices", MPV_FORMAT_NODE_ARRAY);
for (int j = 0; alt[j].name; j++) {
struct mpv_node *ce = node_array_add(choices, MPV_FORMAT_NONE);
ce->format = MPV_FORMAT_STRING;
ce->u.string = talloc_strdup(choices->u.list, alt[j].name);
}
}
} else if (a->defval) {
struct mpv_node *def =
node_map_add(ae, "default-value", MPV_FORMAT_NONE);
m_option_get_node(a, ae->u.list, def, (void *)a->defval);
}
}
node_map_add_flag(entry, "vararg", cmd->vararg);