[add] element:section [add] element:list
This commit is contained in:
parent
0e26fe8078
commit
4ebe7e5b5b
|
|
@ -1,31 +1,64 @@
|
|||
function main() : void
|
||||
async function main(args_raw : Array<string>) : Promise<void>
|
||||
{
|
||||
let element : type_element = element_make(
|
||||
// args
|
||||
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
|
||||
{
|
||||
"kind": "group",
|
||||
"data": {
|
||||
"members": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "foo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "bar"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"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 output : type_output<string> = new type_output_html({});
|
||||
const html : string = output.render_element(element);
|
||||
process.stdout.write(html + "\n");
|
||||
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 element_raw : string = lib_plankton.json.decode(await lib_plankton.file.read(args.input))
|
||||
let element : type_element = element_make(element_raw);
|
||||
|
||||
const output : type_output<string> = output_make<string>({"kind": args.output, "data": {}});
|
||||
|
||||
const result : string = output.render_element(element);
|
||||
process.stdout.write(result + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
main();
|
||||
main(process.argv.slice(2))
|
||||
.then(() => {})
|
||||
.catch((reason) => {process.stderr.write(String(reason));})
|
||||
;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue