git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
e57f32c
Branches
Tags
develop-client_server
master
typescript
fs-words.git
source
main.ts
[mod] main
Christian Fraß
commited
e57f32c
at 2021-03-04 08:18:19
main.ts
Blame
History
Raw
#!/usr/bin/env node /* import {repositories.language} from './repository-language'; import {repositories.type} from './repository-type'; import {repositories.tag} from './repository-tag'; import {repositories.concept} from './repository-concept'; */ function syntaxerror() : void { console.error("-- wrong syntax"); process.exit(1); } /** */ async function main(args : Array<string>) : Promise<void> { const command : string = args.shift(); switch (command) { case "setup": { await repositories.language.setup(); await repositories.type.setup(); await repositories.tag.setup(); await repositories.expression.setup(); await repositories.concept.setup(); process.exit(0); break; } case "show": { const concept_id = parseInt(args.shift()); const exposal : services.concept.type_exposal = await services.concept.expose(concept_id); console.info(helpers.json.encode_extended(exposal, true, 0)); process.exit(0); break; } case "translate": { const language_from : string = args.shift(); const language_to : string = args.shift(); const part : string = args.join(" "); args = []; const result = await services.concept.get_translations ( language_from, language_to, part ); result.forEach ( (entry) => { console.info ( helpers.string.coin ( "[{{language_from}}] {{value_from}} ~ [{{language_to}}] {{value_to}}", { "language_from": entry["language_from"], "value_from": entry["value_from"], "language_to": entry["language_to"], "value_to": entry["value_to"], } ) ); } ); process.exit(0); break; } case "export": { const directory : string = ((args.length >= 1) ? args.shift() : "/tmp"); const result : Array<services.concept.type_exposal> = await services.concept.export_(); const digits : int = 3; for (const exposal of result) { const path : string = helpers.string.coin ( "{{directory}}/concept_{{id}}.json", { "directory": directory, "id": helpers.string.pad_left(exposal.id.toFixed(0), digits, "0"), } ); delete exposal.id; const content : string = helpers.json.encode_extended(exposal, true, 0); await helpers.file.write(path, content); // console.info(path); } console.info(directory); process.exit(0); break; } case "search": { const part : string = args.join(" "); args = []; const result : Array<services.concept.type_exposal> = await services.concept.search(part); result.forEach ( (entry) => { console.info ( helpers.string.coin ( "{{id}} | {{type}} | {{description}} | {{tags}} | {{expressions}}", { "id": entry["id"].toFixed(), "type": entry["type"], "description": (entry["description"] ?? '-'), "tags": entry["tags"].join(","), "expressions": ( () => { let parts : Array<string> = []; for (const [key, value] of Object.entries(entry["expressions"])) { parts.push(key + ":" + value.join("/")); } return parts.join(","); } ) (), } ) ); } ); process.exit(0); break; } case "feed": { const content : string = await helpers.misc.stdin(); const data : any = JSON.parse(content); const concept_thing : any = data; const concept_id : int = await services.concept.suck(concept_thing); console.info(concept_id); process.exit(0); break; } case "new": { if (args.length < 1) { syntaxerror(); } else { const type : string = args.shift(); const tags : Array<string> = ( (args.length >= 1) ? args.shift().split(",") : [] ); const description : string = ( (args.length >= 1) ? args.shift() : null ); const concept_thing : any = { "type": type, "description": description, "tags": tags, "expressions": [], }; const concept_id : int = await services.concept.suck(concept_thing); console.info(concept_id); process.exit(0); } break; } case "set": { if (args.length < 1) { syntaxerror(); } else { const concept_id : int = parseInt(args.shift()); } } default: { console.error("unhandled command: " + command); process.exit(1); break; } } } main(process.argv.slice(2)) .catch ( (error) => { console.error(error.toString()); } );