public inbox for patches@ignore.pl
 help / color / mirror / Atom feed
* [PATCH what] what: add -c option to command-line interface
@ 2026-07-20  7:37 Jakub Slepecki
  2026-07-20 16:00 ` Aki
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Slepecki @ 2026-07-20  7:37 UTC (permalink / raw)
  To: patches; +Cc: please, jakub.slepecki

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH what] what: add -c option to command-line interface
  2026-07-20  7:37 [PATCH what] what: add -c option to command-line interface Jakub Slepecki
@ 2026-07-20 16:00 ` Aki
  0 siblings, 0 replies; 2+ messages in thread
From: Aki @ 2026-07-20 16:00 UTC (permalink / raw)
  To: Jakub Slepecki, patches

On 20/07/2026 09:37, Jakub Slepecki wrote:
> 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>

Merged as 659566ed4e5c8baedbd6563b93e4791ecb603b0d.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-20 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-20  7:37 [PATCH what] what: add -c option to command-line interface Jakub Slepecki
2026-07-20 16:00 ` Aki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox