shim: command line library for lua.

Write scripts as Lua libraries, execute them in the shell.

This is a tiny Lua module that makes it easy to write utilities that work from either bash or Lua.

Usage:

#!/usr/bin/env -S lua -e "require'pkglib'()"
local shim = require'shim'

local mycmd = shim.cmd'mycmd' {
  'arg [type]: documentation',
    arg = 'default-value',
}

--- Optionally overload the constructor
function mycmd.new(T, t)
  -- do validation and construct the raw type.
  return shim.constructNew(T, t)
end

--- Overload what to do when executing cmd.
function mycmd:__call()
  -- do whatever the command is, using its fields.
end

--- Add functions/etc like a normal lua module.
function mycmd.someFunction() ... end

if shim.isMain(mycmd) then mycmd:main(arg) end
return mycmd -- return as library

Mod shim

shim: command line library for lua.

Functions