From: Sami Kerola Date: Sat, 10 Jan 2015 20:07:08 +0000 (+0000) Subject: rtcwake: add --list-modes X-Git-Tag: v2.27-rc1~108 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43a44bfc6da8f4666c5dd6bc03c89713e6c4bd46;p=thirdparty%2Futil-linux.git rtcwake: add --list-modes 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 Signed-off-by: Sami Kerola --- diff --git a/bash-completion/rtcwake b/bash-completion/rtcwake index 51566a2a22..23c774c1fd 100644 --- a/bash-completion/rtcwake +++ b/bash-completion/rtcwake @@ -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') diff --git a/sys-utils/rtcwake.8.in b/sys-utils/rtcwake.8.in index be4a88f4d0..d8acd0aa1f 100644 --- a/sys-utils/rtcwake.8.in +++ b/sys-utils/rtcwake.8.in @@ -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 diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 4b9483cc5b..1044c86db3 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -117,6 +117,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(_(" -d, --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 standby|mem|... sleep mode\n"), out); fputs(_(" -s, --seconds seconds to sleep\n"), out); fputs(_(" -t, --time 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);