timedatectl: convert to VERB_COMMAND

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-13 13:23:05 +02:00
parent 0059c3f5f2
commit 7e2ef99cfb
+8 -50
View File
@@ -24,7 +24,6 @@
#include "parse-argument.h"
#include "parse-util.h"
#include "polkit-agent.h"
#include "pretty-print.h"
#include "runtime-scope.h"
#include "sparse-endian.h"
#include "string-table.h"
@@ -180,6 +179,12 @@ static int print_status_info(const StatusInfo *i) {
return 0;
}
COMMAND(
"timedatectl\0",
.abstract = "Query or change system time and date settings.",
.man_pages = "timedatectl.1\0",
);
VERB_DEFAULT_NOARG(verb_status, "status", "Show current time settings");
static int verb_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
StatusInfo info = {};
@@ -893,54 +898,7 @@ static int verb_revert(int argc, char *argv[], uintptr_t _data, void *userdata)
return 0;
}
static int help(void) {
_cleanup_free_ char *link = NULL;
_cleanup_(table_unrefp) Table *verbs = NULL, *verbs2 = NULL, *options = NULL;
int r;
r = terminal_urlify_man("timedatectl", "1", &link);
if (r < 0)
return log_oom();
r = verbs_get_help_table(&verbs);
if (r < 0)
return r;
r = verbs_get_help_table_group("systemd-timesyncd Commands", &verbs2);
if (r < 0)
return r;
r = option_parser_get_help_table(&options);
if (r < 0)
return r;
(void) table_sync_column_widths(0, verbs, verbs2, options);
printf("%s [OPTIONS...] COMMAND ...\n"
"\n%sQuery or change system time and date settings.%s\n"
"\nCommands:\n",
program_invocation_short_name,
ansi_highlight(),
ansi_normal());
r = table_print_or_warn(verbs);
if (r < 0)
return r;
printf("\nsystemd-timesyncd Commands:\n");
r = table_print_or_warn(verbs2);
if (r < 0)
return r;
printf("\nOptions:\n");
r = table_print_or_warn(options);
if (r < 0)
return r;
printf("\nSee the %s for details.\n", link);
return 0;
}
VERB_COMMON_HELP_HIDDEN(help);
VERB_COMMON_HELP_AUTO_HIDDEN("timedatectl");
static int parse_argv(int argc, char *argv[], char ***ret_args) {
int r;
@@ -953,7 +911,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
FOREACH_OPTION_OR_RETURN(c, &opts)
switch (c) {
OPTION_COMMON_HELP:
return help();
return command_print_help("timedatectl");
OPTION_COMMON_VERSION:
return version();