udevadm-test-builtin: 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-test-builtin" option namespace. The list of built-in commands is appended after the generic help. The man page reference is now printed before the command list. It'd be somewhat nicer to have it _after_, but that'd require a lot of plumbing to split the help generated in two and just doesn't seem worth effort. The list of commands is now printed to stdout (it went to stderr before), arguably a backportable bugfix.
This commit is contained in:
@@ -76,7 +76,7 @@ void udev_builtin_reload(UdevReloadFlags flags) {
|
||||
void udev_builtin_list(void) {
|
||||
FOREACH_ELEMENT(b, builtins)
|
||||
if (*b)
|
||||
fprintf(stderr, " %-14s %s\n", (*b)->name, (*b)->help);
|
||||
printf(" %-14s %s\n", (*b)->name, (*b)->help);
|
||||
}
|
||||
|
||||
const char* udev_builtin_name(UdevBuiltinCommand cmd) {
|
||||
|
||||
@@ -1,39 +1,21 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "device-private.h"
|
||||
#include "device-util.h"
|
||||
#include "format-table.h"
|
||||
#include "help-util.h"
|
||||
#include "log.h"
|
||||
#include "options.h"
|
||||
#include "udev-builtin.h"
|
||||
#include "udevadm.h"
|
||||
#include "udevadm-util.h"
|
||||
#include "verbs.h"
|
||||
|
||||
static sd_device_action_t arg_action = SD_DEVICE_ADD;
|
||||
static const char *arg_command = NULL;
|
||||
static const char *arg_syspath = NULL;
|
||||
|
||||
static int help(void) {
|
||||
_cleanup_(table_unrefp) Table *options = NULL;
|
||||
int r;
|
||||
|
||||
r = option_parser_get_help_table_ns("udevadm-test-builtin", &options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
help_cmdline("test-builtin [OPTIONS] COMMAND DEVPATH");
|
||||
help_abstract("Test a built-in command.");
|
||||
help_section("Options");
|
||||
r = table_print_or_warn(options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
help_section("Commands");
|
||||
udev_builtin_list();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_argv(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
@@ -48,7 +30,13 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
OPTION_NAMESPACE("udevadm-test-builtin"): {}
|
||||
|
||||
OPTION_COMMON_HELP:
|
||||
return help();
|
||||
r = command_print_verb_help("test-builtin");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
help_section("Commands");
|
||||
udev_builtin_list();
|
||||
return 0;
|
||||
|
||||
OPTION('V', "version", NULL, "Show package version"):
|
||||
return print_version();
|
||||
@@ -58,6 +46,9 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (r <= 0)
|
||||
return r;
|
||||
break;
|
||||
|
||||
OPTION_COMMON_INTROSPECT_CLI:
|
||||
return introspect_cli(SD_JSON_FORMAT_OFF);
|
||||
}
|
||||
|
||||
if (option_parser_get_n_args(&opts) != 2)
|
||||
|
||||
Reference in New Issue
Block a user