/** */ async function main( args_raw : Array ) : Promise { const outputs : Record = { "sqlite": output_sqlite, "mysql": output_mysql, "typescript": output_typescript, "jsonschema": output_jsonschema, }; const arg_handler = new lib_plankton.args.class_handler( { "format": new lib_plankton.args.class_argument({ "name": "format", "type": lib_plankton.args.enum_type.string, "kind": lib_plankton.args.enum_kind.volatile, "mode": lib_plankton.args.enum_mode.replace, "default": "sqlite", "parameters": { "indicators_long": ["format"], "indicators_short": ["f"], }, "info": "output format", }), "schema": new lib_plankton.args.class_argument({ "name": "schema", "type": lib_plankton.args.enum_type.boolean, "kind": lib_plankton.args.enum_kind.volatile, "mode": lib_plankton.args.enum_mode.replace, "default": false, "parameters": { "indicators_long": ["schema"], "indicators_short": ["s"], }, "info": "print sindri JSON schema to stdout and exit", }), "help": new lib_plankton.args.class_argument({ "name": "help", "type": lib_plankton.args.enum_type.boolean, "kind": lib_plankton.args.enum_kind.volatile, "mode": lib_plankton.args.enum_mode.replace, "default": false, "parameters": { "indicators_long": ["help"], "indicators_short": ["h"], }, "info": "print help to stdout and exit", }), } ); const args : Record = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" ")); if (args["help"]) { process.stdout.write( arg_handler.generate_help( { "programname": "sindri", "author": "Christian Fraß ", "description": "create data model scripts in different output formats (MySQL, SQLite, …) on basis of an abstract description; feed with .sindri.json file via stdin!", "executable": "sindri", } ) ); } else { if (args["schema"]) { process.stdout.write( JSON.stringify(input_schema(), undefined, "\t") ); } else { const input_content : string = await lib_plankton.file.read_stdin(); const input_data_raw : any = lib_plankton.json.decode(input_content); const input_data : type_input = input_normalize(input_data_raw); 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); } } } } main(process.argv.slice(2));