Skip to content

Commit dc804d8

Browse files
committed
dmiopt: Implement --list-strings and --list-types
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 <[email protected]>
1 parent 6fc53b3 commit dc804d8

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

dmidecode.c

+6
Original file line numberDiff line numberDiff line change
@@ -6155,6 +6155,12 @@ int main(int argc, char * const argv[])
61556155
goto exit_free;
61566156
}
61576157

6158+
if (opt.flags & FLAG_LIST)
6159+
{
6160+
/* Already handled in parse_command_line() */
6161+
goto exit_free;
6162+
}
6163+
61586164
if (opt.flags & FLAG_HELP)
61596165
{
61606166
print_help();

dmiopt.c

+15
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ static u32 parse_opt_handle(const char *arg)
265265
int parse_command_line(int argc, char * const argv[])
266266
{
267267
int option;
268+
unsigned int i;
268269
const char *optstring = "d:hqs:t:uH:V";
269270
struct option longopts[] = {
270271
{ "dev-mem", required_argument, NULL, 'd' },
@@ -279,6 +280,8 @@ int parse_command_line(int argc, char * const argv[])
279280
{ "handle", required_argument, NULL, 'H' },
280281
{ "oem-string", required_argument, NULL, 'O' },
281282
{ "no-sysfs", no_argument, NULL, 'S' },
283+
{ "list-strings", no_argument, NULL, 'L' },
284+
{ "list-types", no_argument, NULL, 'T' },
282285
{ "version", no_argument, NULL, 'V' },
283286
{ NULL, 0, NULL, 0 }
284287
};
@@ -332,6 +335,16 @@ int parse_command_line(int argc, char * const argv[])
332335
case 'S':
333336
opt.flags |= FLAG_NO_SYSFS;
334337
break;
338+
case 'L':
339+
for (i = 0; i < ARRAY_SIZE(opt_string_keyword); i++)
340+
fprintf(stdout, "%s\n", opt_string_keyword[i].keyword);
341+
opt.flags |= FLAG_LIST;
342+
return 0;
343+
case 'T':
344+
for (i = 0; i < ARRAY_SIZE(opt_type_keyword); i++)
345+
fprintf(stdout, "%s\n", opt_type_keyword[i].keyword);
346+
opt.flags |= FLAG_LIST;
347+
return 0;
335348
case 'V':
336349
opt.flags |= FLAG_VERSION;
337350
break;
@@ -377,7 +390,9 @@ void print_help(void)
377390
" -q, --quiet Less verbose output\n"
378391
" --no-quirks Decode everything without quirks\n"
379392
" -s, --string KEYWORD Only display the value of the given DMI string\n"
393+
" --list-strings List available string keywords and exit\n"
380394
" -t, --type TYPE Only display the entries of given type\n"
395+
" --list-types List available type keywords and exit\n"
381396
" -H, --handle HANDLE Only display the entry of given handle\n"
382397
" -u, --dump Do not decode the entries\n"
383398
" --dump-bin FILE Dump the DMI data to a binary file\n"

dmiopt.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern struct opt opt;
4747
#define FLAG_FROM_DUMP (1 << 5)
4848
#define FLAG_NO_SYSFS (1 << 6)
4949
#define FLAG_NO_QUIRKS (1 << 7)
50+
#define FLAG_LIST (1 << 8)
5051

5152
int parse_command_line(int argc, char * const argv[]);
5253
void print_help(void);

man/dmidecode.8

+8
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ typically from files under
127127
.IR /sys/devices/virtual/dmi/id .
128128
Most of these files are even readable by regular users.
129129
.TP
130+
.BR " " " " "--list-strings"
131+
List available string keywords, which can then be passed to the \fB--string\fP
132+
option.
133+
.TP
130134
.BR "-t" ", " "--type \fITYPE\fP"
131135
Only display the entries of type \fITYPE\fP. It can be either a
132136
\s-1DMI\s0 type number, or a comma-separated list of type numbers, or a
@@ -150,6 +154,10 @@ is printed and
150154
.B dmidecode
151155
exits with an error.
152156
.TP
157+
.BR " " " " "--list-types"
158+
List available type keywords, which can then be passed to the \fB--type\fP
159+
option.
160+
.TP
153161
.BR "-H" ", " "--handle \fIHANDLE\fP"
154162
Only display the entry whose handle matches \fIHANDLE\fP.
155163
\fIHANDLE\fP is a 16-bit integer.

0 commit comments

Comments
 (0)