Skip to content

Commit

Permalink
cli: toggle shuffle
Browse files Browse the repository at this point in the history
fixes #197
  • Loading branch information
acrisci committed Nov 3, 2020
1 parent 119d0a5 commit 5bc66df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 6 additions & 3 deletions playerctl/playerctl-cli.c
Expand Up @@ -532,10 +532,13 @@ static gboolean playercmd_shuffle(PlayerctlPlayer *player, gchar **argv, gint ar
status = TRUE;
} else if (strcasecmp(status_str, "off") == 0) {
status = FALSE;
} else if (strcasecmp(status_str, "toggle") == 0) {
g_object_get(player, "shuffle", &status, NULL);
status = !status;
} else {
g_set_error(error, playerctl_cli_error_quark(), 1,
"Got unknown shuffle status: '%s' (expected 'on', "
"or 'off').",
"'off', or 'toggle').",
argv[1]);
return FALSE;
}
Expand Down Expand Up @@ -803,7 +806,7 @@ static const GOptionEntry entries[] = {
{"list-all", 'l', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &list_all_players_and_exit,
"List the names of running players that can be controlled", NULL},
{"no-messages", 's', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &no_status_error_messages,
"Suppress status error messages", NULL},
"Suppress diagnostic messages", NULL},
{"version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &print_version_and_exit,
"Print version information", NULL},
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &command_arg, NULL, "COMMAND"},
Expand Down Expand Up @@ -834,7 +837,7 @@ static gboolean parse_setup_options(int argc, char *argv[], GError **error) {
"\n loop [STATUS] Print or set the loop status."
"\n Can be \"None\", \"Track\", or \"Playlist\"."
"\n shuffle [STATUS] Print or set the shuffle status."
"\n Can be \"On\" or \"Off\".";
"\n Can be \"On\", \"Off\", or \"Toggle\".";

static const gchar *summary = " For players supporting the MPRIS D-Bus specification";
GOptionContext *context = NULL;
Expand Down
19 changes: 16 additions & 3 deletions test/test_commands.py
Expand Up @@ -11,16 +11,29 @@
async def test_commands(bus_address):
[mpris] = await setup_mpris('commands', bus_address=bus_address)

mpris.shuffle = False
mpris.volume = 1.0
mpris.loop_status = 'Track'

commands = ('play', 'pause', 'play-pause', 'stop', 'next', 'previous')
setters = ('volume 0.8', 'loop playlist', 'shuffle on')

def get_called(cmd):
return getattr(mpris, f'{cmd.replace("-", "_")}_called')

playerctl = PlayerctlCli(bus_address)

results = await asyncio.gather(*(playerctl.run(f'-p commands {cmd}')
for cmd in commands))
for cmd in commands + setters))

for i, result in enumerate(results):
cmd = commands[i]
for i, cmd in enumerate(commands):
result = results[i]
assert get_called(cmd), f'{cmd} was not called: {result.stderr}'

assert mpris.shuffle
assert mpris.volume == 0.8
assert mpris.loop_status == 'Playlist'

await playerctl.run('-p commands shuffle toggle')

assert not mpris.shuffle

0 comments on commit 5bc66df

Please sign in to comment.