git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
bc0937f
Branches
Tags
develop-client_server
master
typescript
fs-words.git
source
main.ts
[mod] logic
Christian Fraß
commited
bc0937f
at 2021-03-03 01:35:40
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.concept.setup() process.exit(0); break; } case "show": { const concept_id = parseInt(args.shift()); const concept_entity : entities.concept = await services.concept.get(concept_id); console.info(JSON.stringify(concept_entity, undefined, "\t")); 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 result : Array<any> = await services.concept.export_(); console.info(JSON.stringify(result, undefined, "\t")); process.exit(0); break; } case "search": { const part : string = args.join(" "); args = []; const result = await services.concept.search(part); result.forEach ( (entry) => { console.info ( helpers.string.coin ( "{{id}} | {{type}} | {{description}} | {{tags}} | {{translations}}", { "id": entry["id"].toFixed(), "type": entry["type"], "description": (entry["description"] ?? '-'), "tags": entry["tags"].join(","), "translations": entry["translations"].map(foo => (foo["language"] + ":" + foo["value"])).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, "translations": [], }; 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));