* [PATCH] what: use pl.lapp for what command
@ 2026-05-15 12:45 Jakub Slepecki
2026-05-15 21:12 ` Aki
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Slepecki @ 2026-05-15 12:45 UTC (permalink / raw)
To: patches; +Cc: please, Jakub Slepecki
Penlight's pl.lapp has a very nice interface for users that want to
do `which what` being somewhat self-documenting. It has some minor
problems, it misses some *nix or GNU traditions (e.g., lack of - with
file type that's addressed here) and some quirks like useless newlines.
These sound solvable upstream, but for now we need to wrap them.
No functional changes are done to the command interface. All calls that
were correct are intended to continue being correct.
Remove io.stdin check before closing the input stream. Lua has an
internal check that fails the io.close() returning error message.
We can just ignore it.
Signed-off-by: Jakub Slepecki <jakub.slepecki@intel.com>
---
scripts/install | 6 +++---
what.lua | 17 ++++++++---------
what/lapp.lua | 27 +++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 12 deletions(-)
create mode 100644 what/lapp.lua
diff --git a/scripts/install b/scripts/install
index 545a82a22d37..4b5d73951926 100755
--- a/scripts/install
+++ b/scripts/install
@@ -26,17 +26,17 @@ fi
case $ID in
arch)
[ -n "$buildtime" ] && buildtime=busted
- [ -n "$runtime" ] && runtime=
+ [ -n "$runtime" ] && runtime=lua-penlight
echo pacman -S $buildtime $runtime
;;
debian)
[ -n "$buildtime" ] && buildtime=lua-busted
- [ -n "$runtime" ] && runtime=
+ [ -n "$runtime" ] && runtime=lua-penlight
echo apt install $buildtime $runtime
;;
ubuntu)
[ -n "$buildtime" ] && buildtime=lua-busted
- [ -n "$runtime" ] && runtime=
+ [ -n "$runtime" ] && runtime=lua-penlight
echo apt install $buildtime $runtime
;;
*) echo "ID=$ID" >&2; exit 1;;
diff --git a/what.lua b/what.lua
index 400a908f65ab..cb01fb034170 100755
--- a/what.lua
+++ b/what.lua
@@ -1,12 +1,11 @@
#!/usr/bin/env lua
+local lapp = require "what.lapp"
+local args = lapp[[
+Usage: what [<input>]
+
+ <input> (input default -) Pathname or explicit -
+]]
local config = require "what.config"
local translate = require "what.translate"
-local input = io.stdin
-local pathname = arg[1]
-if pathname and pathname ~= "-" then
- input = io.open(pathname) or error(string.format("%s: could not open: %s", arg[0], pathname))
-end
-translate(config, input)
-if input ~= io.stdin then
- input:close()
-end
+translate(config, args.input)
+io.close(args.input)
diff --git a/what/lapp.lua b/what/lapp.lua
new file mode 100644
index 000000000000..81bbd27a0294
--- /dev/null
+++ b/what/lapp.lua
@@ -0,0 +1,27 @@
+--- Extension module for Penlight's pl.lapp.
+local lapp = require "pl.lapp"
+
+
+--- Built-in file type from pl.lapp has minor limitations. For one, it does not
+--- support "-" as filename as an alias for standard input. We do that here.
+---
+--- User must io.close() the file themselves.
+lapp.add_type(
+ "input",
+ function (name)
+ if not name or name == "-" then
+ return io.stdin
+ end
+ return io.open(name, "r") or name
+ end,
+ function (handle)
+ if io.type(handle) ~= "file" then
+ io.stderr:write(
+ string.format("what: could not open: %s\n", handle))
+ os.exit(1)
+ -- lapp.error() prints useless newline
+ end
+ end)
+
+
+return lapp
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] what: use pl.lapp for what command
2026-05-15 12:45 [PATCH] what: use pl.lapp for what command Jakub Slepecki
@ 2026-05-15 21:12 ` Aki
0 siblings, 0 replies; 2+ messages in thread
From: Aki @ 2026-05-15 21:12 UTC (permalink / raw)
To: Jakub Slepecki, patches
On 15/05/2026 14:45, Jakub Slepecki wrote:
> Penlight's pl.lapp has a very nice interface for users that want to
> do `which what` being somewhat self-documenting. It has some minor
> problems, it misses some *nix or GNU traditions (e.g., lack of - with
> file type that's addressed here) and some quirks like useless newlines.
> These sound solvable upstream, but for now we need to wrap them.
>
> No functional changes are done to the command interface. All calls that
> were correct are intended to continue being correct.
>
> Remove io.stdin check before closing the input stream. Lua has an
> internal check that fails the io.close() returning error message.
> We can just ignore it.
>
> Signed-off-by: Jakub Slepecki <jakub.slepecki@intel.com>
Merged as 96b9b70d6415.
Corrected a small type "User (...) themselves" -> "Users (...) themselves.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-15 21:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-15 12:45 [PATCH] what: use pl.lapp for what command Jakub Slepecki
2026-05-15 21:12 ` Aki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox