~fgaz/minetest-declarative_chatcmd

bf60126cba999547db3e1cc9d3a13714e9c44670 — Francesco Gazzetta 1 year, 19 days ago a0d35ad master
doc mod support
3 files changed, 23 insertions(+), 1 deletions(-)

M README.md
M init.lua
M mod.conf
M README.md => README.md +5 -0
@@ 5,6 5,11 @@
TODO links to source, forum, cdb...
TODO some documentation!

## Optional dependencies

* `doc`: If present, a "Commands (declarative_chatcmd)" help category will be
  added, containing an entry for each declared command with its full help text.

## License

Licensed under the EUPL, see the [LICENSE](./LICENSE) file.

M init.lua => init.lua +17 -1
@@ 8,9 8,25 @@ local runner = dofile(minetest.get_modpath(modname) .. "/src/runner.lua")
-- MAYBE validate the spec first (eg. no subcommands and args at the same time)
-- TODO actually... both _can_ be there if subcommands are last!! though it should probably be discouraged...
function declarative_chatcmd.register_chatcommand(name, spec)
  local description = help.make_description(name, spec)

  if doc then
    -- NOTE: we don't check if the category already exists, multiple calls are
    -- allowed
    doc.add_category(modname .. ":commands", {
      name = "Commands (" .. modname .. ")",
      description = "Commands declared through " .. modname,
      build_formspec = doc.entry_builders.text,
    })
    doc.add_entry(modname .. ":commands", modname .. ":commands:" .. name, {
      name = "/" .. name,
      data = description,
    })
  end

  return minetest.register_chatcommand(name, {
    params = help.make_params_string(spec),
    description = help.make_description(name, spec),
    description = description,
    privs = spec.privs or {}, -- we also check the privs here for good measure
    func = runner.make_func(name, spec),
  })

M mod.conf => mod.conf +1 -0
@@ 2,5 2,6 @@ name = declarative_chatcmd
title = Declarative Chat Command Builder
description = A library to build chat commands (including help text) from lua table descriptions
depends =
optional_depends = doc
# Not actually tested, but it should be at least 5.2.0, when get_modpath() was introduced
min_minetest_version = 5.2.0