diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-03-13 18:12:04 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-03-16 16:46:44 +0100 |
commit | 5356761da67aa5c11f784c3ba9ac8d8f6e55048b (patch) | |
tree | 970588a1d900622bc063c410f42ae905de55db3c /src/udev/cdrom_id | |
parent | bd36d0281ab41bfea932931e913809ee1e6195ed (diff) | |
download | systemd-5356761da67aa5c11f784c3ba9ac8d8f6e55048b.tar.gz |
udev: implement --version in all builtins
Those are separate binaries, and occasionally people will get a misplaced
binary that doesn't match the rest of the installed system and be confused, so
it good to be able to check the version. It is also nice to have the same
interface in all binaries.
Note that we usually use a separate 'enum ARG_VERSION = 0x100' for an option
without a short name. We can use a less verbose approach of simply taking any
unused letter, which works just as well and even the compiler would warn us
if we tried to use the letter in another place. This way we avoid a few lines
of boilerplate.
The help texts are adjusted to have an empty line between the synopsis and
option list, and no empty lines after the option list.
Diffstat (limited to 'src/udev/cdrom_id')
-rw-r--r-- | src/udev/cdrom_id/cdrom_id.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 3d58100f3e..5b5fbd0109 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -10,6 +10,7 @@ #include <sys/ioctl.h> #include <unistd.h> +#include "build.h" #include "fd-util.h" #include "main-func.h" #include "memory-util.h" @@ -897,13 +898,13 @@ static void print_properties(const Context *c) { } static int help(void) { - printf("Usage: %s [options] <device>\n" - " -l --lock-media lock the media (to enable eject request events)\n" - " -u --unlock-media unlock the media\n" - " -e --eject-media eject the media\n" - " -d --debug print debug messages to stderr\n" - " -h --help print this help text\n" - "\n", + printf("%s [OPTIONS...] DEVICE\n\n" + " -l --lock-media Lock the media (to enable eject request events)\n" + " -u --unlock-media Unlock the media\n" + " -e --eject-media Eject the media\n" + " -d --debug Print debug messages to stderr\n" + " -h --help Show this help text\n" + " --version Show package version\n", program_invocation_short_name); return 0; @@ -916,6 +917,7 @@ static int parse_argv(int argc, char *argv[]) { { "eject-media", no_argument, NULL, 'e' }, { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, {} }; int c; @@ -938,6 +940,8 @@ static int parse_argv(int argc, char *argv[]) { break; case 'h': return help(); + case 'v': + return version(); case '?': return -EINVAL; default: |