diff options
-rw-r--r-- | src/rspamadm/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/rspamadm/confighelp.c | 17 | ||||
-rw-r--r-- | src/rspamadm/confighelp.lua | 42 |
3 files changed, 58 insertions, 5 deletions
diff --git a/src/rspamadm/CMakeLists.txt b/src/rspamadm/CMakeLists.txt index 258ed454b..3f8a3d0c3 100644 --- a/src/rspamadm/CMakeLists.txt +++ b/src/rspamadm/CMakeLists.txt @@ -15,7 +15,9 @@ SET(RSPAMADMSRC rspamadm.c ${CMAKE_SOURCE_DIR}/src/smtp_proxy.c ${CMAKE_SOURCE_DIR}/src/worker.c ${CMAKE_SOURCE_DIR}/src/http_proxy.c) -SET(RSPAMADMLUASRC ${CMAKE_CURRENT_SOURCE_DIR}/fuzzy_stat.lua) +SET(RSPAMADMLUASRC + ${CMAKE_CURRENT_SOURCE_DIR}/fuzzy_stat.lua + ${CMAKE_CURRENT_SOURCE_DIR}/confighelp.lua) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) ADD_CUSTOM_TARGET(rspamadm_lua_preprocess ${PERL_EXECUTABLE} diff --git a/src/rspamadm/confighelp.c b/src/rspamadm/confighelp.c index 462d6ff50..870676e9f 100644 --- a/src/rspamadm/confighelp.c +++ b/src/rspamadm/confighelp.c @@ -29,6 +29,7 @@ #include "cfg_rcl.h" #include "rspamd.h" #include "lua/lua_common.h" +#include "confighelp.lua.h" static gboolean json = FALSE; static gboolean compact = FALSE; @@ -81,7 +82,8 @@ rspamadm_confighelp_help (gboolean full_help) } static void -rspamadm_confighelp_show (const char *key, const ucl_object_t *obj) +rspamadm_confighelp_show (struct rspamd_config *cfg, gint argc, gchar **argv, + const char *key, const ucl_object_t *obj) { rspamd_fstring_t *out; @@ -103,7 +105,14 @@ rspamadm_confighelp_show (const char *key, const ucl_object_t *obj) rspamd_fprintf (stdout, "Showing help for all options:\n"); } - rspamd_ucl_emit_fstring (obj, UCL_EMIT_CONFIG, &out); + rspamadm_execute_lua_ucl_subr (cfg->lua_state, + argc, + argv, + obj, + rspamadm_script_confighelp); + + rspamd_fstring_free (out); + return; } rspamd_fprintf (stdout, "%V", out); @@ -245,7 +254,7 @@ rspamadm_confighelp (gint argc, gchar **argv) } if (doc_obj != NULL) { - rspamadm_confighelp_show (argv[i], doc_obj); + rspamadm_confighelp_show (cfg, argc, argv, argv[i], doc_obj); if (keyword) { ucl_object_unref ((ucl_object_t *)doc_obj); @@ -265,7 +274,7 @@ rspamadm_confighelp (gint argc, gchar **argv) } else { /* Show all documentation strings */ - rspamadm_confighelp_show (NULL, cfg->doc_strings); + rspamadm_confighelp_show (cfg, argc, argv, NULL, cfg->doc_strings); } rspamd_config_free (cfg); diff --git a/src/rspamadm/confighelp.lua b/src/rspamadm/confighelp.lua new file mode 100644 index 000000000..34f323f28 --- /dev/null +++ b/src/rspamadm/confighelp.lua @@ -0,0 +1,42 @@ +local util = require "rspamd_util" +local opts = {} +local known_attrs = { + data = 1, + example = 1, + type = 1 +} + +--.USE "getopt" + +local function print_help(key, value, tabs) + print(string.format('%sOption: %s', tabs, key)) + + if not opts['short'] then + if value['data'] then + print(string.format('%s\tDescription: %s', tabs, value['data'])) + end + if value['type'] then + print(string.format('%s\tType: %s', tabs, value['type'])) + end + + if not opts['no-examples'] and value['example'] then + print(string.format('%s\tExample: %s', tabs, value['example'])) + end + end + print('') + + for k, v in pairs(value) do + if not known_attrs[k] then + -- We need to go deeper + print_help(k, v, tabs .. '\t') + end + end +end + +return function(args, res) + opts = getopt(args, '') + + for k,v in pairs(res) do + print_help(k, v, ''); + end +end |