Skip to content

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

Open
zenodity wants to merge 1 commit intompv-player:masterfrom
zenodity:extend-command-list
Open

player/command: add default-value/choices arg fields to command-list#17516
zenodity wants to merge 1 commit intompv-player:masterfrom
zenodity:extend-command-list

Conversation

@zenodity
Copy link
Contributor

@zenodity zenodity commented Mar 7, 2026

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.

Aligns command-list schema with option-info schema.

Partial output from libmpv "command-list" property:

[{
	"name": "seek",
	"args": [{
			"name": "target",
			"type": "Time",
			"optional": false
		}, {
			"name": "flags",
			"type": "Flags",
			"optional": false,
			"default-value": "relative",
			"choices": ["relative", "-", "absolute-percent", "absolute", "relative-percent", "keyframes", "exact"]
		}, {
			"name": "legacy",
			"type": "Choice",
			"optional": true,
			"choices": ["unused", "default-precise", "keyframes", "exact"]
		}
	],
	"vararg": false
}, {
	"name": "frame-step",
	"args": [{
			"name": "frames",
			"type": "Integer",
			"optional": false,
			"default-value": 1
		}, {
			"name": "flags",
			"type": "Choice",
			"optional": true,
			"choices": ["play", "seek", "mute"]
		}
	],
	"vararg": false
}]

@guidocella
Copy link
Contributor

This is great for commands.lua which currently hardcodes flags.

player/command.c Outdated
node_map_add_string(ae, "type", a->type->name);
node_map_add_flag(ae, "optional", a->flags & MP_CMD_OPT_ARG);
if (a->defval) {
if (a->type == &m_option_type_int) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use m_option_get_node to avoid this ladder of conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Ready for testing.

player/command.c Outdated
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(NULL, alt[j].name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this strdup is not parented to anything, so we're leaking here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i've fixed this. @kasper93 has said he will test this later.

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.
@zenodity zenodity force-pushed the extend-command-list branch from a6c8195 to b500854 Compare March 9, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants