From: Jakub Slepecki <jakub.slepecki@intel.com>
To: patches@ignore.pl
Cc: please@ignore.pl, jakub.slepecki@intel.com
Subject: [PATCH what] what: add -c option to command-line interface
Date: Mon, 20 Jul 2026 09:37:21 +0200 [thread overview]
Message-ID: <20260720073721.14907-1-jakub.slepecki@intel.com> (raw)
Using require() to load configuration gives some interesting effects,
for example, one can add their own what.config in a directory that is
tested earlier to inject their own configuration. This avoids some
logic needed for a custom config loading behaviour. In a long run,
a "traditional" XDG_CONFIG_HOME, HOME, ... may be better, but this is
enough to start tinkering with plugins and such.
Signed-off-by: Jakub Slepecki <jakub.slepecki@intel.com>
---
what.1 | 11 ++++++++++-
what.lua | 6 +++---
what/lapp.lua | 14 ++++++++++++++
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/what.1 b/what.1
index af6b18b84b0e..d65028fd656d 100644
--- a/what.1
+++ b/what.1
@@ -3,6 +3,8 @@
what - translates raw information in logs to something human-readable
.SH SYNPOSIS
.B what
+.RB [ \-c
+.IR config ]
.RI [ file ]
.SH DESCRIPTION
Translate various blobs or otherwise intangible information into a
@@ -10,8 +12,15 @@ human-readable format.
.P
.I File
argument may be pathname or
-.B -
+.B \-
to read from standard input. If left empty it will also read from
standard input.
+.SH OPTIONS
+.B \-c
+.I config
+.RS
+Use a custom configuration module. Default is
+.BI what.config .
+.RE
.SH SEE ALSO
.BR dmesg (1)
diff --git a/what.lua b/what.lua
index cb01fb034170..b26ff459408c 100755
--- a/what.lua
+++ b/what.lua
@@ -1,11 +1,11 @@
#!/usr/bin/env lua
local lapp = require "what.lapp"
local args = lapp[[
-Usage: what [<input>]
+Usage: what [-c] [<input>]
+ -c (module default what.config) What config to use
<input> (input default -) Pathname or explicit -
]]
-local config = require "what.config"
local translate = require "what.translate"
-translate(config, args.input)
+translate(args.c, args.input)
io.close(args.input)
diff --git a/what/lapp.lua b/what/lapp.lua
index 2d27ea7a7960..3e2bb75794d7 100644
--- a/what/lapp.lua
+++ b/what/lapp.lua
@@ -24,4 +24,18 @@ lapp.add_type(
end)
+lapp.add_type(
+ "module",
+ function (name)
+ local ok, module = pcall(require, name)
+ print(name, ok, module)
+ if not ok then
+ io.stderr:write(
+ string.format("what: could not load module: %s\n", name))
+ os.exit(1)
+ end
+ return module
+ end)
+
+
return lapp
--
2.43.0
next reply other threads:[~2026-07-20 7:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 7:37 Jakub Slepecki [this message]
2026-07-20 16:00 ` Aki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260720073721.14907-1-jakub.slepecki@intel.com \
--to=jakub.slepecki@intel.com \
--cc=patches@ignore.pl \
--cc=please@ignore.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox