feat: add cat command

builtins
TorchedSammy 2022-10-14 19:09:45 -04:00
parent f3964ce389
commit 373d2e4f82
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 26 additions and 1 deletions

View File

@ -75,7 +75,7 @@ disables commands being added to history.
- A new and "safer" event emitter has been added. This causes a performance deficit, but avoids a lot of
random errors introduced with the new Lua runtime (see [#197])
- `bait.release(name, catcher)` removes `handler` for the named `event`
- `exec` and `clear` builtin commands
- `exec`, `clear` and `cat` builtin commands
[#197]: https://github.com/Rosettea/Hilbish/issues/197

View File

@ -0,0 +1,25 @@
local commander = require 'commander'
local fs = require 'fs'
commander.register('cat', function(args)
local exit = 0
if #args == 0 then
print [[
usage: cat [file]...]]
end
for _, fName in ipairs(args) do
local f = io.open(fName)
if f == nil then
exit = 1
print(string.format('cat: %s: no such file or directory', fName))
goto continue
end
io.write(f:read '*a')
::continue::
end
io.flush()
return exit
end)