dmidecode-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] dmiopt: Implement --list-strings and --list-types


From: Jean Delvare
Subject: [PATCH] dmiopt: Implement --list-strings and --list-types
Date: Mon, 9 Oct 2023 12:21:38 +0200

Implement options to list string and type keywords, respectively.
These can be used to feed shell completion scripts for example.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
Ville, I think this would make implementing the dmidecode bash
completion script slightly easier?

 dmidecode.c     |    6 ++++++
 dmiopt.c        |   16 +++++++++++++++-
 dmiopt.h        |    1 +
 man/dmidecode.8 |    8 ++++++++
 4 files changed, 30 insertions(+), 1 deletion(-)

--- dmidecode.orig/dmidecode.c
+++ dmidecode/dmidecode.c
@@ -6155,6 +6155,12 @@ int main(int argc, char * const argv[])
                goto exit_free;
        }
 
+       if (opt.flags & FLAG_LIST)
+       {
+               /* Already handled in parse_command_line() */
+               goto exit_free;
+       }
+
        if (opt.flags & FLAG_HELP)
        {
                print_help();
--- dmidecode.orig/dmiopt.c
+++ dmidecode/dmiopt.c
@@ -265,6 +265,7 @@ static u32 parse_opt_handle(const char *
 int parse_command_line(int argc, char * const argv[])
 {
        int option;
+       unsigned int i;
        const char *optstring = "d:hqs:t:uH:V";
        struct option longopts[] = {
                { "dev-mem", required_argument, NULL, 'd' },
@@ -279,6 +280,8 @@ int parse_command_line(int argc, char *
                { "handle", required_argument, NULL, 'H' },
                { "oem-string", required_argument, NULL, 'O' },
                { "no-sysfs", no_argument, NULL, 'S' },
+               { "list-strings", no_argument, NULL, 'L' },
+               { "list-types", no_argument, NULL, 'T' },
                { "version", no_argument, NULL, 'V' },
                { NULL, 0, NULL, 0 }
        };
@@ -332,6 +335,16 @@ int parse_command_line(int argc, char *
                        case 'S':
                                opt.flags |= FLAG_NO_SYSFS;
                                break;
+                       case 'L':
+                               for (i = 0; i < ARRAY_SIZE(opt_string_keyword); 
i++)
+                                       fprintf(stdout, "%s\n", 
opt_string_keyword[i].keyword);
+                               opt.flags |= FLAG_LIST;
+                               return 0;
+                       case 'T':
+                               for (i = 0; i < ARRAY_SIZE(opt_type_keyword); 
i++)
+                                       fprintf(stdout, "%s\n", 
opt_type_keyword[i].keyword);
+                               opt.flags |= FLAG_LIST;
+                               return 0;
                        case 'V':
                                opt.flags |= FLAG_VERSION;
                                break;
@@ -377,13 +390,14 @@ void print_help(void)
                " -q, --quiet            Less verbose output\n"
                "     --no-quirks        Decode everything without quirks\n"
                " -s, --string KEYWORD   Only display the value of the given 
DMI string\n"
+               "     --list-strings     List available string keywords and 
exit\n"
                " -t, --type TYPE        Only display the entries of given 
type\n"
+               "     --list-types       List available type keywords and 
exit\n"
                " -H, --handle HANDLE    Only display the entry of given 
handle\n"
                " -u, --dump             Do not decode the entries\n"
                "     --dump-bin FILE    Dump the DMI data to a binary file\n"
                "     --from-dump FILE   Read the DMI data from a binary file\n"
                "     --no-sysfs         Do not attempt to read DMI data from 
sysfs files\n"
-               "     --oem-string N     Only display the value of the given 
OEM string\n"
                " -V, --version          Display the version and exit\n";
 
        printf("%s", help);
--- dmidecode.orig/dmiopt.h
+++ dmidecode/dmiopt.h
@@ -47,6 +47,7 @@ extern struct opt opt;
 #define FLAG_FROM_DUMP          (1 << 5)
 #define FLAG_NO_SYSFS           (1 << 6)
 #define FLAG_NO_QUIRKS          (1 << 7)
+#define FLAG_LIST               (1 << 8)
 
 int parse_command_line(int argc, char * const argv[]);
 void print_help(void);
--- dmidecode.orig/man/dmidecode.8
+++ dmidecode/man/dmidecode.8
@@ -127,6 +127,10 @@ typically from files under
 .IR /sys/devices/virtual/dmi/id .
 Most of these files are even readable by regular users.
 .TP
+.BR "  " "  " "--list-strings"
+List available string keywords, which can then be passed to the \fB--string\fP
+option.
+.TP
 .BR "-t" ", " "--type \fITYPE\fP"
 Only display the entries of type \fITYPE\fP. It can be either a
 \s-1DMI\s0 type number, or a comma-separated list of type numbers, or a
@@ -150,6 +154,10 @@ is printed and
 .B dmidecode
 exits with an error.
 .TP
+.BR "  " "  " "--list-types"
+List available type keywords, which can then be passed to the \fB--type\fP
+option.
+.TP
 .BR "-H" ", " "--handle \fIHANDLE\fP"
 Only display the entry whose handle matches \fIHANDLE\fP.
 \fIHANDLE\fP is a 16-bit integer.


-- 
Jean Delvare
SUSE L3 Support



reply via email to

[Prev in Thread] Current Thread [Next in Thread]