keyutil: convert to VERB_COMMAND and add --introspect-cli

The custom help() is replaced by a COMMAND() description, and
--introspect-cli is added.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-17 15:49:01 +02:00
parent 2908468b39
commit 618aa83e18
2 changed files with 13 additions and 48 deletions
+12 -48
View File
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "sd-json.h"
#include "alloc-util.h"
#include "ask-password-api.h"
#include "build.h"
@@ -7,13 +9,10 @@
#include "dlopen-note.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-table.h"
#include "fs-util.h"
#include "log.h"
#include "main-func.h"
#include "options.h"
#include "parse-argument.h"
#include "pretty-print.h"
#include "string-util.h"
#include "tmpfile-util.h"
#include "verbs.h"
@@ -37,51 +36,13 @@ STATIC_DESTRUCTOR_REGISTER(arg_signature, freep);
STATIC_DESTRUCTOR_REGISTER(arg_content, freep);
STATIC_DESTRUCTOR_REGISTER(arg_output, freep);
static int help(void) {
_cleanup_free_ char *link = NULL;
_cleanup_(table_unrefp) Table *options = NULL, *verbs = NULL;
int r;
COMMAND(
"systemd-keyutil\0",
"Perform various operations on private keys and certificates.",
.man_pages = "systemd-keyutil.1\0",
);
r = terminal_urlify_man("systemd-keyutil", "1", &link);
if (r < 0)
return log_oom();
r = verbs_get_help_table(&verbs);
if (r < 0)
return r;
r = option_parser_get_help_table(&options);
if (r < 0)
return r;
(void) table_sync_column_widths(0, verbs, options);
printf("%s [OPTIONS...] COMMAND ...\n\n"
"%sPerform various operations on private keys and certificates.%s\n"
"\n%sCommands:%s\n",
program_invocation_short_name,
ansi_highlight(),
ansi_normal(),
ansi_underline(),
ansi_normal());
r = table_print_or_warn(verbs);
if (r < 0)
return r;
printf("\n%sOptions:%s\n",
ansi_underline(),
ansi_normal());
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("systemd-keyutil");
static int parse_argv(int argc, char *argv[], char ***ret_args) {
assert(argc >= 0);
@@ -95,7 +56,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
switch (c) {
OPTION_COMMON_HELP:
return help();
return command_print_help("systemd-keyutil");
OPTION_COMMON_VERSION:
return version();
@@ -152,6 +113,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
if (r < 0)
return r;
break;
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(SD_JSON_FORMAT_OFF);
}
if (arg_private_key_source && !arg_certificate)
@@ -47,6 +47,7 @@ INTROSPECTABLE=(
systemd-journal-gatewayd
systemd-journal-remote
systemd-journal-upload
systemd-keyutil
systemd-modules-load
systemd-mute-console
systemd-network-generator