]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rtcwake: add --list-modes
authorSami Kerola <kerolasa@iki.fi>
Sat, 10 Jan 2015 20:07:08 +0000 (20:07 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 29 Jun 2015 11:39:37 +0000 (13:39 +0200)
Commit ece44f19f423408f576f348fed2845c876d72c6e missed freeze mode, which
to a simple patch adding the missing argument but Karel pointed out it
would be better to make the rtcwake to tell what arguments are supported
so that possible changes end up to be automatically correct in bash
completion.

Proposed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
bash-completion/rtcwake
sys-utils/rtcwake.8.in
sys-utils/rtcwake.c

index 51566a2a225a6dedfa1b21725b2b490a7d3a77d9..23c774c1fd9a44e565ca74368e415e20d160d4b2 100644 (file)
@@ -12,7 +12,7 @@ _rtcwake_module()
                        return 0
                        ;;
                '-m'|'--mode')
-                       COMPREPLY=( $(compgen -W "standby mem disk off no on disable show" -- $cur) )
+                       COMPREPLY=( $(compgen -W "$(rtcwake --list-modes)" -- $cur) )
                        return 0
                        ;;
                '-s'|'--seconds')
index be4a88f4d0a692fc6e180bd9162e8c1370e28fdd..d8acd0aa1f30d07716868d80ea92536f0c6e8b98 100644 (file)
@@ -16,7 +16,7 @@
 .\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 .\" 02110-1301, USA.
 .\"
-.TH RTCWAKE 8 "July 2014" "util-linux" "System Administration"
+.TH RTCWAKE 8 "June 2015" "util-linux" "System Administration"
 .SH NAME
 rtcwake \- enter a system sleep state until specified wakeup time
 .SH SYNOPSIS
@@ -78,6 +78,9 @@ You may specify \fBrtc1\fP, \fBrtc2\fP, ... here.
 Assume that the hardware clock is set to local time, regardless of the
 contents of the \fIadjtime\fP file.
 .TP
+.B \-\-list\-modes
+List available \-\-mode option arguments.
+.TP
 .BR \-m , " \-\-mode " \fImode
 Go into the given standby state.  Valid values for \fImode\fP are:
 .RS
index 4b9483cc5b34d5b77624f1b9f496efb93b41d80b..1044c86db36ea804ce0709040631bbcc9d570ce9 100644 (file)
@@ -117,6 +117,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" -d, --device <device>    select rtc device (rtc0|rtc1|...)\n"), out);
        fputs(_(" -n, --dry-run            does everything, but suspend\n"), out);
        fputs(_(" -l, --local              RTC uses local timezone\n"), out);
+       fputs(_("     --list-modes         list available modes\n"), out);
        fputs(_(" -m, --mode <mode>        standby|mem|... sleep mode\n"), out);
        fputs(_(" -s, --seconds <seconds>  seconds to sleep\n"), out);
        fputs(_(" -t, --time <time_t>      time to wake\n"), out);
@@ -395,6 +396,15 @@ static int open_dev_rtc(const char *devname)
        return fd;
 }
 
+static void list_modes(void)
+{
+       int i = ARRAY_SIZE(mode_str);
+
+       while (i--)
+               printf("%s%s", mode_str[i], i == 0 ? "" : " ");
+       putchar('\n');
+}
+
 int main(int argc, char **argv)
 {
        struct rtcwake_control ctl = {
@@ -413,7 +423,8 @@ int main(int argc, char **argv)
        time_t          alarm = 0;
 
        enum {
-               OPT_DATE = CHAR_MAX + 1
+               OPT_DATE = CHAR_MAX + 1,
+               OPT_LIST
        };
 
        static const struct option long_options[] = {
@@ -430,6 +441,7 @@ int main(int argc, char **argv)
                {"seconds",     required_argument,      0, 's'},
                {"time",        required_argument,      0, 't'},
                {"date",        required_argument,      0, OPT_DATE},
+               {"list-modes",  no_argument,            0, OPT_LIST},
                {0,             0,                      0, 0  }
        };
 
@@ -458,6 +470,10 @@ int main(int argc, char **argv)
                        ctl.clock_mode = CM_LOCAL;
                        break;
 
+               case OPT_LIST:
+                       list_modes();
+                       return EXIT_SUCCESS;
+
                case 'm':
                        if ((suspend = get_mode(optarg)) < 0)
                                errx(EXIT_FAILURE, _("unrecognized suspend state '%s'"), optarg);