]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: implement --version in all builtins
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 13 Mar 2023 17:12:04 +0000 (18:12 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 16 Mar 2023 15:46:44 +0000 (16:46 +0100)
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.

man/udevadm.xml
src/udev/ata_id/ata_id.c
src/udev/cdrom_id/cdrom_id.c
src/udev/dmi_memory_id/dmi_memory_id.c
src/udev/fido_id/fido_id.c
src/udev/mtd_probe/mtd_probe.c
src/udev/v4l_id/v4l_id.c

index 503ec8109184e89019dbb8d56c71922ca2fbf214..e520c98143a5a86e8cb7dfb806751713e43309a1 100644 (file)
         </varlistentry>
 
         <xi:include href="standard-options.xml" xpointer="help" />
+        <xi:include href="standard-options.xml" xpointer="version" />
       </variablelist>
     </refsect2>
 
index ec472feada354633bde2f196abccd7690909f0dd..7760d248cfb6aac69ab176b4b95663270d7ad55c 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "build.h"
 #include "device-nodes.h"
 #include "fd-util.h"
 #include "log.h"
@@ -361,8 +362,9 @@ static int disk_identify(int fd,
 
 static int parse_argv(int argc, char *argv[]) {
         static const struct option options[] = {
-                { "export", no_argument, NULL, 'x' },
-                { "help",   no_argument, NULL, 'h' },
+                { "export",   no_argument, NULL, 'x' },
+                { "help",     no_argument, NULL, 'h' },
+                { "version",  no_argument, NULL, 'v' },
                 {}
         };
         int c;
@@ -375,9 +377,12 @@ static int parse_argv(int argc, char *argv[]) {
                 case 'h':
                         printf("%s [OPTIONS...] DEVICE\n\n"
                                "  -x --export    Print values as environment keys\n"
-                               "  -h --help      Show this help text\n",
+                               "  -h --help      Show this help text\n"
+                               "     --version   Show package version\n",
                                program_invocation_short_name);
                         return 0;
+                case 'v':
+                        return version();
                 case '?':
                         return -EINVAL;
                 default:
index 3d58100f3e5ffe56560e2241bb43b62adc3d1f31..5b5fbd0109aa2b5d8215ca829c556bf67a3d5909 100644 (file)
@@ -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:
index 1345289219e4dcdb8027ee387cdecfe779372308..dd46113137c91211638af1e9563ddd5d30531dd8 100644 (file)
@@ -45,6 +45,7 @@
 #include <getopt.h>
 
 #include "alloc-util.h"
+#include "build.h"
 #include "fileio.h"
 #include "main-func.h"
 #include "string-util.h"
@@ -638,9 +639,10 @@ static int legacy_decode(const uint8_t *buf, const char *devmem, bool no_file_of
 }
 
 static int help(void) {
-        printf("Usage: %s [options]\n"
-               " -F,--from-dump FILE   read DMI information from a binary file\n"
-               " -h,--help             print this help text\n\n",
+        printf("%s [OPTIONS...]\n\n"
+               "  -F --from-dump FILE  Read DMI information from a binary file\n"
+               "  -h --help            Show this help text\n"
+               "     --version         Show package version\n",
                program_invocation_short_name);
         return 0;
 }
@@ -650,6 +652,7 @@ static int parse_argv(int argc, char * const *argv) {
                 { "from-dump", required_argument, NULL, 'F' },
                 { "version",   no_argument,       NULL, 'V' },
                 { "help",      no_argument,       NULL, 'h' },
+                { "version",   no_argument,       NULL, 'v' },
                 {}
         };
         int c;
@@ -666,6 +669,8 @@ static int parse_argv(int argc, char * const *argv) {
                         return help();
                 case '?':
                         return -EINVAL;
+                case 'v':
+                        return version();
                 default:
                         assert_not_reached();
                 }
index 11f5320d2bb2c879af90f3ebcaf8afa2ccb679a7..e01f37d04c4c372b35968e191d522bcc30de372c 100644 (file)
@@ -15,6 +15,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include "build.h"
 #include "device-private.h"
 #include "device-util.h"
 #include "fd-util.h"
@@ -30,7 +31,8 @@ static const char *arg_device = NULL;
 
 static int parse_argv(int argc, char *argv[]) {
         static const struct option options[] = {
-                { "help",   no_argument, NULL, 'h' },
+                { "help",     no_argument, NULL, 'h' },
+                { "version",  no_argument, NULL, 'v' },
                 {}
         };
         int c;
@@ -39,9 +41,12 @@ static int parse_argv(int argc, char *argv[]) {
                 switch (c) {
                 case 'h':
                         printf("%s [OPTIONS...] SYSFS_PATH\n\n"
-                               "  -h --help     Show this help text\n",
+                               "  -h --help     Show this help text\n"
+                               "     --version  Show package version\n",
                                program_invocation_short_name);
                         return 0;
+                case 'v':
+                        return version();
                 case '?':
                         return -EINVAL;
                 default:
index 513491ed6cfd5d2e8fdcef3ebbffa648a42347a4..1035320490af1420c0995e0c5b154ac59258b07f 100644 (file)
@@ -30,6 +30,7 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "build.h"
 #include "fd-util.h"
 #include "main-func.h"
 #include "mtd_probe.h"
@@ -38,7 +39,8 @@ static const char *arg_device = NULL;
 
 static int parse_argv(int argc, char *argv[]) {
         static const struct option options[] = {
-                { "help",   no_argument, NULL, 'h' },
+                { "help",     no_argument, NULL, 'h' },
+                { "version",  no_argument, NULL, 'v' },
                 {}
         };
         int c;
@@ -47,9 +49,12 @@ static int parse_argv(int argc, char *argv[]) {
                 switch (c) {
                 case 'h':
                         printf("%s /dev/mtd[n]\n\n"
-                               "  -h --help     Show this help text\n",
+                               "  -h --help     Show this help text\n"
+                               "     --version  Show package version\n",
                                program_invocation_short_name);
                         return 0;
+                case 'v':
+                        return version();
                 case '?':
                         return -EINVAL;
                 default:
index 98075db0ce23f93f04b3ceff7e8cdbe04cba513b..1d176a387e5145724bef8359f4fa34dec2b7c206 100644 (file)
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <linux/videodev2.h>
 
+#include "build.h"
 #include "fd-util.h"
 #include "main-func.h"
 
@@ -33,7 +34,8 @@ static const char *arg_device = NULL;
 
 static int parse_argv(int argc, char *argv[]) {
         static const struct option options[] = {
-                { "help", no_argument, NULL, 'h' },
+                { "help",     no_argument, NULL, 'h' },
+                { "version",  no_argument, NULL, 'v' },
                 {}
         };
         int c;
@@ -43,9 +45,12 @@ static int parse_argv(int argc, char *argv[]) {
                 case 'h':
                         printf("%s [OPTIONS...] DEVICE\n\n"
                                "Video4Linux device identification.\n\n"
-                               "  -h --help     Show this help text\n",
+                               "  -h --help     Show this help text\n"
+                               "     --version  Show package version\n",
                                program_invocation_short_name);
                         return 0;
+                case 'v':
+                        return version();
                 case '?':
                         return -EINVAL;
                 default: