commit 1eae758b91513b27c60d26c95197dce14d82e837 from: Omar Polo date: Wed Jul 13 09:36:27 2022 UTC make the on|off argument to consume/repeat optional commit - 9881c98ce0817889c42c9ad4146d7e1db91d7005 commit + 1eae758b91513b27c60d26c95197dce14d82e837 blob - bd5b87e3d780e7debfe2aeba5290d0e25f106023 blob + 5c0b4524fcdd3652cce21a91456e7130214c5366 --- amused.1 +++ amused.1 @@ -58,7 +58,7 @@ The following commands are available: .Bl -tag -width Ds .It Cm add Ar Enqueue the given files. -.It Cm consume on|off +.It Cm consume Op Cm on|off When consume mode is enabled the tracks are removed from the playlist once played til the end. .It Cm flush @@ -123,7 +123,7 @@ Pause the playback. Start or resume the playback. .It Cm prev Play the previous song. -.It Cm repeat one|all on|off +.It Cm repeat one|all Op Cm on|off Enable or disable the automatic repetition of the current track .Pq Cm one or of the whole playing queue blob - 3b01942b95ad0d506ded27942f2fd37969377e64 blob + 7032cdbb6c9dcf55ac90a35172f995c1aa2d204d --- ctl.c +++ ctl.c @@ -657,35 +657,37 @@ ctl_jump(struct parse_result *res, int argc, char **ar res->files = argv; return ctlaction(res); +} + +static int +parse_mode(struct parse_result *res, const char *v) +{ + if (v == NULL) + return MODE_TOGGLE; + if (!strcmp(v, "on")) + return MODE_ON; + if (!strcmp(v, "off")) + return MODE_OFF; + ctl_usage(res->ctl); } static int ctl_repeat(struct parse_result *res, int argc, char **argv) { - int ch, b; + int ch; while ((ch = getopt(argc, argv, "")) != -1) ctl_usage(res->ctl); argc -= optind; argv += optind; - if (argc != 2) - ctl_usage(res->ctl); - - if (!strcmp(argv[1], "on")) - b = 1; - else if (!strcmp(argv[1], "off")) - b = 0; - else + if (argc != 1 && argc != 2) ctl_usage(res->ctl); - res->mode.repeat_one = -1; - res->mode.repeat_all = -1; - res->mode.consume = -1; if (!strcmp(argv[0], "one")) - res->mode.repeat_one = b; + res->mode.repeat_one = parse_mode(res, argv[1]); else if (!strcmp(argv[0], "all")) - res->mode.repeat_all = b; + res->mode.repeat_all = parse_mode(res, argv[1]); else ctl_usage(res->ctl); @@ -702,12 +704,10 @@ ctl_consume(struct parse_result *res, int argc, char * argc -= optind; argv += optind; - if (argc != 1) + if (argc > 1) ctl_usage(res->ctl); - res->mode.repeat_one = -1; - res->mode.repeat_all = -1; - res->mode.consume = !strcmp(argv[0], "on"); + res->mode.consume = parse_mode(res, argv[0]); return ctlaction(res); } @@ -965,6 +965,10 @@ ctl(int argc, char **argv) fmt = "status,time,repeat"; res.status_format = fmt; + res.mode.consume = MODE_UNDEF; + res.mode.repeat_all = MODE_UNDEF; + res.mode.repeat_one = MODE_UNDEF; + log_init(1, LOG_DAEMON); log_setverbose(verbose);