[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",
|
"input": lib_plankton.args.class_argument.positional({
|
||||||
"data": {
|
"index": 0,
|
||||||
"members": [
|
"type": lib_plankton.args.enum_type.string,
|
||||||
{
|
"mode": lib_plankton.args.enum_mode.replace,
|
||||||
"kind": "text",
|
"default": null,
|
||||||
"data": {
|
"info": "path to input file",
|
||||||
"content": "foo"
|
"name": "input",
|
||||||
}
|
}),
|
||||||
},
|
"output": lib_plankton.args.class_argument.volatile({
|
||||||
{
|
"indicators_long": ["output"],
|
||||||
"kind": "text",
|
"indicators_short": ["o"],
|
||||||
"data": {
|
"type": lib_plankton.args.enum_type.string,
|
||||||
"content": "bar"
|
"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 args : Record<string, any> = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" "));
|
||||||
const html : string = output.render_element(element);
|
// process.stdout.write(JSON.stringify(args)); return;
|
||||||
process.stdout.write(html + "\n");
|
|
||||||
|
// 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