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

The custom help() is replaced by a COMMAND() description, and
--introspect-cli is added. The abstract loses its odd capitalization
("Display and process credentials."). --help now goes through the pager,
like other commands with --no-pager.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-17 15:49:01 +02:00
parent 6f63f2074e
commit e6858b9b31
2 changed files with 14 additions and 48 deletions
+13 -48
View File
@@ -7,6 +7,7 @@
#include "sd-varlink.h"
#include "alloc-util.h"
#include "ansi-color.h"
#include "build.h"
#include "bus-polkit.h"
#include "bus-util.h"
@@ -24,12 +25,10 @@
#include "log.h"
#include "main-func.h"
#include "memory-util.h"
#include "options.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "polkit-agent.h"
#include "pretty-print.h"
#include "stat-util.h"
#include "string-table.h"
#include "string-util.h"
@@ -79,6 +78,13 @@ static bool arg_ask_password = true;
STATIC_DESTRUCTOR_REGISTER(arg_tpm2_public_key, freep);
STATIC_DESTRUCTOR_REGISTER(arg_tpm2_signature, freep);
COMMAND(
"systemd-creds\0",
"Display and process credentials.",
.man_pages = "systemd-creds.1\0",
.pager_flags = &arg_pager_flags,
);
static const char* transcode_mode_table[_TRANSCODE_MAX] = {
[TRANSCODE_OFF] = "off",
[TRANSCODE_BASE64] = "base64",
@@ -773,51 +779,7 @@ static int verb_has_tpm2(int argc, char *argv[], uintptr_t _data, void *userdata
return verb_has_tpm2_generic(arg_quiet);
}
static int help(void) {
_cleanup_free_ char *link = NULL;
_cleanup_(table_unrefp) Table *options = NULL, *verbs = NULL;
int r;
r = terminal_urlify_man("systemd-creds", "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"
"%sDisplay and Process Credentials.%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(help);
VERB_COMMON_HELP_AUTO("systemd-creds");
static int parse_argv(int argc, char *argv[], char ***ret_args) {
assert(argc >= 0);
@@ -830,7 +792,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
switch (c) {
OPTION_COMMON_HELP:
return help();
return command_print_help("systemd-creds");
OPTION_COMMON_VERSION:
return version();
@@ -1022,6 +984,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
OPTION('q', "quiet", NULL, "Suppress informational messages"):
arg_quiet = true;
break;
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(arg_json_format_flags);
}
SET_FLAG(arg_credential_flags, CREDENTIAL_IPC_ALLOW_INTERACTIVE, arg_ask_password);
@@ -28,6 +28,7 @@ INTROSPECTABLE=(
systemd-cgls
systemd-cgtop
systemd-clonesetup
systemd-creds
systemd-delta
systemd-detect-virt
systemd-dissect