From c23175163be2bab469724e30a0f03b9725be5a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Sun, 18 May 2025 04:46:37 +0000 Subject: [PATCH] [add] conf-schema exposition --- source/conf.ts | 5 +- source/main.ts | 127 +++++++++++++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 55 deletions(-) diff --git a/source/conf.ts b/source/conf.ts index 8a7e1af..de7c6eb 100644 --- a/source/conf.ts +++ b/source/conf.ts @@ -652,8 +652,8 @@ namespace _munin.conf /** */ - function schema( - version : string + export function schema( + version : string = "3" ) : lib_plankton.conf.type_schema { switch (version) { @@ -679,7 +679,6 @@ namespace _munin.conf }; break; } - default: case "2": case "3": { return { diff --git a/source/main.ts b/source/main.ts index 30dbd8d..194f0e0 100644 --- a/source/main.ts +++ b/source/main.ts @@ -176,6 +176,15 @@ namespace _munin "info": "path to configuration file", "name": "conf-path", }), + "conf_schema": lib_plankton.args.class_argument.volatile({ + "indicators_long": ["conf-schema"], + "indicators_short": ["s"], + "type": lib_plankton.args.enum_type.string, + "mode": lib_plankton.args.enum_mode.replace, + "default": "", + "info": "only print the configuration schema in a specific version (latest version via argument '_')", + "name": "conf-schema", + }), "conf_expose": lib_plankton.args.class_argument.volatile({ "indicators_long": ["conf-expose"], "indicators_short": ["e"], @@ -187,11 +196,11 @@ namespace _munin }), "single_run": lib_plankton.args.class_argument.volatile({ "indicators_long": ["single-run"], - "indicators_short": ["s"], + "indicators_short": ["x"], "type": lib_plankton.args.enum_type.boolean, "mode": lib_plankton.args.enum_mode.replace, "default": false, - "info": "whether to only execute on iteration at run", + "info": "whether to only execute one iteration at run", "name": "single-run", }), "verbosity": lib_plankton.args.class_argument.volatile({ @@ -240,46 +249,10 @@ namespace _munin ); } else { - // init - const conf : _munin.conf.type_conf = await _munin.conf.load(args.conf_path); - lib_plankton.log.set_main_logger( - [ - { - "kind": "filtered", - "data": { - "core": { - "kind": "std", - "data": { - "target": "stdout", - "format": { - "kind": "human_readable", - "data": { - } - } - } - }, - "predicate": [ - [ - { - "item": { - "kind": "level", - "data": { - "threshold": args.verbosity, - } - }, - }, - ] - ], - } - }, - ] - ); - - // exec - if (args.conf_expose) { + if (args.conf_schema !== "") { process.stdout.write( lib_plankton.json.encode( - conf, + _munin.conf.schema((args.conf_schema === "_") ? undefined : args.conf_schema), { "formatted": true, } @@ -288,20 +261,70 @@ namespace _munin "\n" ); } - switch (/*args.action*/"run") { - default: { - throw (new Error("unhandled action: " + args.action)); - break; - } - case "run": { - run( - conf, + else { + // init + const conf : _munin.conf.type_conf = await _munin.conf.load(args.conf_path); + lib_plankton.log.set_main_logger( + [ { - "single_run": args.single_run, - "dry_run": args.dry_run, - } + "kind": "filtered", + "data": { + "core": { + "kind": "std", + "data": { + "target": "stdout", + "format": { + "kind": "human_readable", + "data": { + } + } + } + }, + "predicate": [ + [ + { + "item": { + "kind": "level", + "data": { + "threshold": args.verbosity, + } + }, + }, + ] + ], + } + }, + ] + ); + + // exec + if (args.conf_expose) { + process.stdout.write( + lib_plankton.json.encode( + conf, + { + "formatted": true, + } + ) + + + "\n" ); - break; + } + switch (/*args.action*/"run") { + default: { + throw (new Error("unhandled action: " + args.action)); + break; + } + case "run": { + run( + conf, + { + "single_run": args.single_run, + "dry_run": args.dry_run, + } + ); + break; + } } } }