[add] conf-schema exposition

This commit is contained in:
Christian Fraß 2025-05-18 04:46:37 +00:00
parent 196ee61fd9
commit c23175163b
2 changed files with 77 additions and 55 deletions

View file

@ -652,8 +652,8 @@ namespace _munin.conf
/** /**
*/ */
function schema( export function schema(
version : string version : string = "3"
) : lib_plankton.conf.type_schema ) : lib_plankton.conf.type_schema
{ {
switch (version) { switch (version) {
@ -679,7 +679,6 @@ namespace _munin.conf
}; };
break; break;
} }
default:
case "2": case "2":
case "3": { case "3": {
return { return {

View file

@ -176,6 +176,15 @@ namespace _munin
"info": "path to configuration file", "info": "path to configuration file",
"name": "conf-path", "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({ "conf_expose": lib_plankton.args.class_argument.volatile({
"indicators_long": ["conf-expose"], "indicators_long": ["conf-expose"],
"indicators_short": ["e"], "indicators_short": ["e"],
@ -187,11 +196,11 @@ namespace _munin
}), }),
"single_run": lib_plankton.args.class_argument.volatile({ "single_run": lib_plankton.args.class_argument.volatile({
"indicators_long": ["single-run"], "indicators_long": ["single-run"],
"indicators_short": ["s"], "indicators_short": ["x"],
"type": lib_plankton.args.enum_type.boolean, "type": lib_plankton.args.enum_type.boolean,
"mode": lib_plankton.args.enum_mode.replace, "mode": lib_plankton.args.enum_mode.replace,
"default": false, "default": false,
"info": "whether to only execute on iteration at run", "info": "whether to only execute one iteration at run",
"name": "single-run", "name": "single-run",
}), }),
"verbosity": lib_plankton.args.class_argument.volatile({ "verbosity": lib_plankton.args.class_argument.volatile({
@ -239,6 +248,19 @@ namespace _munin
) )
); );
} }
else {
if (args.conf_schema !== "") {
process.stdout.write(
lib_plankton.json.encode(
_munin.conf.schema((args.conf_schema === "_") ? undefined : args.conf_schema),
{
"formatted": true,
}
)
+
"\n"
);
}
else { else {
// init // init
const conf : _munin.conf.type_conf = await _munin.conf.load(args.conf_path); const conf : _munin.conf.type_conf = await _munin.conf.load(args.conf_path);
@ -305,6 +327,7 @@ namespace _munin
} }
} }
} }
}
return Promise.resolve<void>(undefined); return Promise.resolve<void>(undefined);
} }