44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
|
|
async function main(
|
||
|
|
args_raw : Array<string>
|
||
|
|
) : Promise<void>
|
||
|
|
{
|
||
|
|
const outputs : Record<string, type_output> = {
|
||
|
|
"sqlite": output_sqlite,
|
||
|
|
"mysql": output_mysql,
|
||
|
|
};
|
||
|
|
|
||
|
|
const arg_handler = new lib_args.class_handler(
|
||
|
|
{
|
||
|
|
"format": new lib_args.class_argument({
|
||
|
|
"name": "format",
|
||
|
|
"type": lib_args.enum_type.string,
|
||
|
|
"kind": lib_args.enum_kind.volatile,
|
||
|
|
"mode": lib_args.enum_mode.replace,
|
||
|
|
"default": "sqlite",
|
||
|
|
"parameters": {
|
||
|
|
"indicators_long": ["format"],
|
||
|
|
"indicators_short": ["f"],
|
||
|
|
},
|
||
|
|
"info": "output format",
|
||
|
|
}),
|
||
|
|
}
|
||
|
|
);
|
||
|
|
const args : Record<string, any> = arg_handler.read(lib_args.enum_environment.cli, args_raw.join(" "));
|
||
|
|
|
||
|
|
const input_content : string = await lib_plankton.file.read_stdin();
|
||
|
|
const input_data : type_input_data = lib_json.decode(input_content);
|
||
|
|
|
||
|
|
// TODO: sanitize & normalize input_data
|
||
|
|
|
||
|
|
if (! outputs.hasOwnProperty(args["format"])) {
|
||
|
|
throw (new Error("unhandled output format: " + args["format"]));
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
const output_content : string = outputs[args["format"]].render(input_data);
|
||
|
|
process.stdout.write(output_content);
|
||
|
|
// return Promise.resolve<void>(undefined);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
main(process.argv.slice(2));
|