udevadm: getopt() and help message cleanup

This adds missing options, mainly '--version' in getopt(), removes
an unused option from getopt().
Also, this adds a deprecate message in `udevadm hwdb`, and cleanups
help messages.

Follow-up for 65eb4378c3.
This commit is contained in:
Yu Watanabe 2017-12-05 23:30:10 +09:00
parent a135d27105
commit 5639df9a80
9 changed files with 80 additions and 35 deletions

View file

@ -24,12 +24,13 @@
#include "time-util.h"
#include "udev-util.h"
#include "udev.h"
#include "udevadm-util.h"
static void print_help(void) {
printf("%s control COMMAND\n\n"
printf("%s control OPTION\n\n"
"Control the udev daemon.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -V --version Show package version\n"
" -e --exit Instruct the daemon to cleanup and exit\n"
" -l --log-priority=LEVEL Set the udev log level for the daemon\n"
" -s --stop-exec-queue Do not execute events, queue only\n"
@ -57,6 +58,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
{ "env", required_argument, NULL, 'p' }, /* alias for -p */
{ "children-max", required_argument, NULL, 'm' },
{ "timeout", required_argument, NULL, 't' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{}
};
@ -70,7 +72,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
if (uctrl == NULL)
return 2;
while ((c = getopt_long(argc, argv, "el:sSRp:m:h", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "el:sSRp:m:t:Vh", options, NULL)) >= 0)
switch (c) {
case 'e':
if (udev_ctrl_send_exit(uctrl, timeout) < 0)
@ -153,6 +155,10 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
}
break;
}
case 'V':
print_version();
rc = 0;
break;
case 'h':
print_help();
rc = 0;

View file

@ -34,6 +34,7 @@
#include "strbuf.h"
#include "string-util.h"
#include "udev.h"
#include "udevadm-util.h"
#include "util.h"
/*
@ -546,12 +547,17 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam
}
static void help(void) {
printf("Usage: udevadm hwdb OPTIONS\n"
" -u,--update update the hardware database\n"
" --usr generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
" -t,--test=MODALIAS query database and print result\n"
" -r,--root=PATH alternative root path in the filesystem\n"
" -h,--help\n\n");
printf("%s hwdb [OPTIONS]\n\n"
" -h --help Print this message\n"
" -V --version Print version of the program\n"
" -u --update Update the hardware database\n"
" --usr Generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
" -t --test=MODALIAS Query database and print result\n"
" -r --root=PATH Alternative root path in the filesystem\n\n"
"NOTE:\n"
"The sub-command 'hwdb' is deprecated, and is left for backwards compatibility.\n"
"Please use systemd-hwdb instead.\n"
, program_invocation_short_name);
}
static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
@ -560,11 +566,12 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
};
static const struct option options[] = {
{ "update", no_argument, NULL, 'u' },
{ "usr", no_argument, NULL, ARG_USR },
{ "test", required_argument, NULL, 't' },
{ "root", required_argument, NULL, 'r' },
{ "help", no_argument, NULL, 'h' },
{ "update", no_argument, NULL, 'u' },
{ "usr", no_argument, NULL, ARG_USR },
{ "test", required_argument, NULL, 't' },
{ "root", required_argument, NULL, 'r' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{}
};
const char *test = NULL;
@ -575,7 +582,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
int err, c;
int rc = EXIT_SUCCESS;
while ((c = getopt_long(argc, argv, "ut:r:h", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "ut:r:Vh", options, NULL)) >= 0)
switch(c) {
case 'u':
update = true;
@ -589,6 +596,9 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
case 'r':
root = optarg;
break;
case 'V':
print_version();
return EXIT_SUCCESS;
case 'h':
help();
return EXIT_SUCCESS;

View file

@ -377,7 +377,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) {
export_prefix = optarg;
break;
case 'V':
printf("%s\n", PACKAGE_VERSION);
print_version();
return 0;
case 'h':
help();

View file

@ -30,6 +30,7 @@
#include "format-util.h"
#include "udev-util.h"
#include "udev.h"
#include "udevadm-util.h"
static bool udev_exit;
@ -60,10 +61,10 @@ static void print_device(struct udev_device *device, const char *source, int pro
}
static void help(void) {
printf("%s monitor [--property] [--kernel] [--udev] [--help]\n\n"
printf("%s monitor [OPTIONS]\n\n"
"Listen to kernel and udev events.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -V --version Show package version\n"
" -p --property Print the event properties\n"
" -k --kernel Print kernel uevents\n"
" -u --udev Print udev events\n"
@ -94,6 +95,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
{ "udev", no_argument, NULL, 'u' },
{ "subsystem-match", required_argument, NULL, 's' },
{ "tag-match", required_argument, NULL, 't' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{}
};
@ -101,7 +103,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
udev_list_init(udev, &subsystem_match_list, true);
udev_list_init(udev, &tag_match_list, true);
while ((c = getopt_long(argc, argv, "pekus:t:h", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "pekus:t:Vh", options, NULL)) >= 0)
switch (c) {
case 'p':
case 'e':
@ -130,6 +132,9 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
case 't':
udev_list_entry_add(&tag_match_list, optarg, NULL);
break;
case 'V':
print_version();
return 0;
case 'h':
help();
return 0;

View file

@ -29,13 +29,14 @@
#include "parse-util.h"
#include "udev.h"
#include "udevadm-util.h"
#include "util.h"
static void help(void) {
printf("%s settle OPTIONS\n\n"
printf("%s settle [OPTIONS]\n\n"
"Wait for pending udev events.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -V --version Show package version\n"
" -t --timeout=SECONDS Maximum time to wait for events\n"
" -E --exit-if-exists=FILE Stop waiting if file exists\n"
, program_invocation_short_name);
@ -45,6 +46,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
static const struct option options[] = {
{ "timeout", required_argument, NULL, 't' },
{ "exit-if-exists", required_argument, NULL, 'E' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ "seq-start", required_argument, NULL, 's' }, /* removed */
{ "seq-end", required_argument, NULL, 'e' }, /* removed */
@ -59,7 +61,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
struct udev_queue *queue;
int rc = EXIT_FAILURE;
while ((c = getopt_long(argc, argv, "t:E:hs:e:q", options, NULL)) >= 0) {
while ((c = getopt_long(argc, argv, "t:E:Vhs:e:q", options, NULL)) >= 0) {
switch (c) {
case 't': {
@ -77,6 +79,10 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
exists = optarg;
break;
case 'V':
print_version();
return EXIT_SUCCESS;
case 'h':
help();
return EXIT_SUCCESS;

View file

@ -25,12 +25,13 @@
#include "path-util.h"
#include "string-util.h"
#include "udev.h"
#include "udevadm-util.h"
static void help(struct udev *udev) {
printf("%s builtin [--help] COMMAND SYSPATH\n\n"
printf("%s test-builtin [OPTIONS] COMMAND DEVPATH\n\n"
"Test a built-in command.\n\n"
" -h --help Print this message\n"
" --version Print version of the program\n\n"
" -V --version Print version of the program\n\n"
"Commands:\n"
, program_invocation_short_name);
@ -39,7 +40,8 @@ static void help(struct udev *udev) {
static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{}
};
char *command = NULL;
@ -49,8 +51,11 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
enum udev_builtin_cmd cmd;
int rc = EXIT_SUCCESS, c;
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "Vh", options, NULL)) >= 0)
switch (c) {
case 'V':
print_version();
goto out;
case 'h':
help(udev);
goto out;

View file

@ -29,13 +29,14 @@
#include "string-util.h"
#include "udev-util.h"
#include "udev.h"
#include "udevadm-util.h"
static void help(void) {
printf("%s test OPTIONS <syspath>\n\n"
"Test an event run.\n"
printf("%s test [OPTIONS] DEVPATH\n\n"
"Test an event run.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -V --version Show package version\n"
" -a --action=ACTION Set action string\n"
" -N --resolve-names=early|late|never When to resolve names\n"
, program_invocation_short_name);
@ -54,15 +55,16 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
int rc = 0, c;
static const struct option options[] = {
{ "action", required_argument, NULL, 'a' },
{ "action", required_argument, NULL, 'a' },
{ "resolve-names", required_argument, NULL, 'N' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{}
};
log_debug("version %s", PACKAGE_VERSION);
while ((c = getopt_long(argc, argv, "a:N:h", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0)
switch (c) {
case 'a':
action = optarg;
@ -80,6 +82,9 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
break;
case 'V':
print_version();
exit(EXIT_SUCCESS);
case 'h':
help();
exit(EXIT_SUCCESS);

View file

@ -68,10 +68,10 @@ static const char *keyval(const char *str, const char **val, char *buf, size_t s
}
static void help(void) {
printf("%s trigger OPTIONS\n\n"
printf("%s trigger [OPTIONS] DEVPATH\n\n"
"Request events from the kernel.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -V --version Show package version\n"
" -v --verbose Print the list of devices while running\n"
" -n --dry-run Do not actually trigger the events\n"
" -t --type= Type of events to trigger\n"
@ -109,6 +109,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
{ "sysname-match", required_argument, NULL, 'y' },
{ "name-match", required_argument, NULL, ARG_NAME },
{ "parent-match", required_argument, NULL, 'b' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{}
};
@ -124,7 +125,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
if (udev_enumerate == NULL)
return 1;
while ((c = getopt_long(argc, argv, "vno:t:c:s:S:a:A:p:g:y:b:h", options, NULL)) >= 0) {
while ((c = getopt_long(argc, argv, "vnt:c:s:S:a:A:p:g:y:b:Vh", options, NULL)) >= 0) {
const char *key;
const char *val;
char buf[UTIL_PATH_SIZE];
@ -240,6 +241,9 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
break;
}
case 'V':
print_version();
return 0;
case 'h':
help();
return 0;

View file

@ -23,3 +23,7 @@
struct udev_device *find_device(struct udev *udev,
const char *id,
const char *prefix);
static inline void print_version(void) {
printf("%s\n", PACKAGE_VERSION);
}