dfhack/plugins/lua/misery.lua

44 lines
997 B
Lua

2023-02-08 15:02:44 -07:00
local _ENV = mkmodule('plugins.misery')
local argparse = require('argparse')
local function process_args(opts, args)
if args[1] == 'help' then
opts.help = true
return
end
return argparse.processArgsGetopt(args, {
{'h', 'help', handler=function() opts.help = true end},
})
end
function status()
print(('misery is %s'):format(isEnabled() and "enabled" or "disabled"))
print(('misery factor is: %d'):format(misery_getFactor()))
end
function parse_commandline(...)
local args, opts = {...}, {}
local positionals = process_args(opts, args)
2023-12-31 01:24:12 -07:00
if opts.help or not positionals then
2023-02-08 15:02:44 -07:00
return false
end
local command = table.remove(positionals, 1)
if not command or command == 'status' then
status()
elseif command == 'clear' then
misery_clear()
2023-12-31 01:24:12 -07:00
elseif tonumber(command) then
misery_setFactor(tonumber(command))
2023-02-08 15:02:44 -07:00
else
return false
end
return true
end
return _ENV