udevadm-hwdb: use common verb help and add --introspect-cli
The custom help() is replaced by the common verb help, which derives the synopsis, abstract, and option list from the verb declaration in udevadm.c and the "udevadm-control" option namespace. The new VERB_DEPRECATED flag is used.
This commit is contained in:
+6
-25
@@ -1,13 +1,12 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "format-table.h"
|
||||
#include "help-util.h"
|
||||
#include "hwdb-util.h"
|
||||
#include "log.h"
|
||||
#include "options.h"
|
||||
#include "udevadm.h"
|
||||
#include "verbs.h"
|
||||
|
||||
static const char *arg_test = NULL;
|
||||
static const char *arg_root = NULL;
|
||||
@@ -15,27 +14,6 @@ static const char *arg_hwdb_bin_dir = NULL;
|
||||
static bool arg_update = false;
|
||||
static bool arg_strict = false;
|
||||
|
||||
static int help(void) {
|
||||
_cleanup_(table_unrefp) Table *options = NULL;
|
||||
int r;
|
||||
|
||||
r = option_parser_get_help_table_ns("udevadm-hwdb", &options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
help_cmdline("hwdb [OPTIONS]");
|
||||
help_abstract("Update or query the hardware database.");
|
||||
help_section("Options");
|
||||
r = table_print_or_warn(options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
printf("\nNOTE:\n"
|
||||
"The sub-command 'hwdb' is deprecated, and is left for backwards compatibility.\n"
|
||||
"Please use systemd-hwdb instead.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_argv(int argc, char *argv[]) {
|
||||
assert(argc >= 0);
|
||||
assert(argv);
|
||||
@@ -48,7 +26,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
OPTION_NAMESPACE("udevadm-hwdb"): {}
|
||||
|
||||
OPTION_COMMON_HELP:
|
||||
return help();
|
||||
return command_print_verb_help("hwdb");
|
||||
|
||||
OPTION('V', "version", NULL, "Show package version"):
|
||||
return print_version();
|
||||
@@ -74,6 +52,9 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
OPTION('r', "root", "PATH", "Alternative root path in the filesystem"):
|
||||
arg_root = opts.arg;
|
||||
break;
|
||||
|
||||
OPTION_COMMON_INTROSPECT_CLI:
|
||||
return introspect_cli(SD_JSON_FORMAT_OFF);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
+2
-1
@@ -40,7 +40,8 @@ UDEVADM_VERB(verb_verify_main, "verify", "[FILE…]\0", 0,
|
||||
UDEVADM_VERB(verb_cat_main, "cat", "[FILE…]\0", 0, "Show udev rules files", NULL);
|
||||
UDEVADM_VERB(verb_wait_main, "wait", "DEVICE [DEVICE…]\0", 0, "Wait for device or device symlink", NULL);
|
||||
UDEVADM_VERB(verb_lock_main, "lock", "COMMAND", 0, "Lock a block device", NULL);
|
||||
UDEVADM_VERB(verb_hwdb_main, "hwdb", NULL, 0, /* help= */ NULL, NULL); /* deprecated */
|
||||
UDEVADM_VERB(verb_hwdb_main, "hwdb", NULL, VERB_DEPRECATED, "Update or query the hardware database",
|
||||
"Verb 'hwdb' is deprecated. Use systemd-hwdb instead.");
|
||||
|
||||
VERB_NOARG(verb_version_main, "version", /* help= */ NULL);
|
||||
static int verb_version_main(int argc, char *argv[], uintptr_t _data, void *userdata) {
|
||||
|
||||
@@ -214,6 +214,10 @@ udevadm --introspect-cli | jq -e \
|
||||
'.commands[] | select(.names[0] == "udevadm") | .verbs[] | select(.names[0] == "info") |
|
||||
[.options[].names[-1]] | contains(["--query", "--json", "--no-pager"])'
|
||||
|
||||
udevadm --introspect-cli | jq -e \
|
||||
'.commands[] | select(.names[0] == "udevadm") | .verbs[] |
|
||||
select(.names[0] == "hwdb") | .isDeprecated == true'
|
||||
|
||||
# systemd is optionally a multicall binary that also provides systemd-executor
|
||||
if [[ "$(readlink "$(command -v systemd-executor)" 2>/dev/null)" == systemd ]]; then
|
||||
systemd --introspect-cli | jq -e \
|
||||
|
||||
Reference in New Issue
Block a user