66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
async function main(args_raw : Array<string>) : Promise<void>
|
|
{
|
|
// args
|
|
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
|
|
{
|
|
"input": lib_plankton.args.class_argument.positional({
|
|
"index": 0,
|
|
"type": lib_plankton.args.enum_type.string,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": null,
|
|
"info": "path to input file",
|
|
"name": "input",
|
|
}),
|
|
"output": lib_plankton.args.class_argument.volatile({
|
|
"indicators_long": ["output"],
|
|
"indicators_short": ["o"],
|
|
"type": lib_plankton.args.enum_type.string,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": "html",
|
|
"info": "output format",
|
|
"name": "output",
|
|
}),
|
|
"help": lib_plankton.args.class_argument.volatile({
|
|
"indicators_long": ["help"],
|
|
"indicators_short": ["h"],
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
"default": false,
|
|
"info": "show help",
|
|
"name": "help",
|
|
}),
|
|
}
|
|
);
|
|
const args : Record<string, any> = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" "));
|
|
// process.stdout.write(JSON.stringify(args)); return;
|
|
|
|
// exec
|
|
if (args.help)
|
|
{
|
|
process.stdout.write(
|
|
arg_handler.generate_help(
|
|
{
|
|
}
|
|
)
|
|
);
|
|
}
|
|
else
|
|
{
|
|
const document_raw : string = lib_plankton.json.decode(await lib_plankton.file.read(args.input))
|
|
const document : type_document = type_document.from_raw(document_raw);
|
|
// let object : type_object = object_make(document_raw["content"]["main"]);
|
|
|
|
const output : type_output<string> = output_make<string>({"kind": args.output, "data": {}});
|
|
|
|
const result : string = output.render_document(document);
|
|
process.stdout.write(result + "\n");
|
|
}
|
|
}
|
|
|
|
|
|
main(process.argv.slice(2))
|
|
.then(() => {})
|
|
.catch((reason) => {process.stderr.write(String(reason));})
|
|
;
|
|
|