bc0937fc7190a2c8deb910a37f330ffd30cc04b4
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

1) #!/usr/bin/env node
2) 
3) /*
4) import {repositories.language} from './repository-language';
5) import {repositories.type} from './repository-type';
6) import {repositories.tag} from './repository-tag';
7) import {repositories.concept} from './repository-concept';
8)  */
9) 
10) 
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

11) function syntaxerror() : void
12) {
13) 	console.error("-- wrong syntax");
14) 	process.exit(1);
15) }
16) 
17) 
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

18) /**
19)  */
20) async function main(args : Array<string>) : Promise<void>
21) {
22) 	const command : string = args.shift();
23) 	switch (command)
24) 	{
25) 		case "setup":
26) 		{
27) 			await repositories.language.setup()
28) 			await repositories.type.setup()
29) 			await repositories.tag.setup()
30) 			await repositories.concept.setup()
31) 			process.exit(0);
32) 			break;
33) 		}
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

34) 		case "show":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

35) 		{
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

36) 			const concept_id = parseInt(args.shift());
37) 			const concept_entity : entities.concept = await services.concept.get(concept_id);
38) 			console.info(JSON.stringify(concept_entity, undefined, "\t"));
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

39) 			process.exit(0);
40) 			break;
41) 		}
42) 		case "translate":
43) 		{
44) 			const language_from : string = args.shift();
45) 			const language_to : string = args.shift();
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

46) 			const part : string = args.join(" "); args = [];
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

47) 			const result = await services.concept.get_translations
48) 			(
49) 				language_from,
50) 				language_to,
51) 				part
52) 			);
53) 			result.forEach
54) 			(
55) 				(entry) =>
56) 				{
57) 					console.info
58) 					(
59) 						helpers.string.coin
60) 						(
61) 							"[{{language_from}}] {{value_from}} ~ [{{language_to}}] {{value_to}}",
62) 							{
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

63) 								"language_from": entry["language_from"],
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

64) 								"value_from": entry["value_from"],
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

65) 								"language_to": entry["language_to"],
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

66) 								"value_to": entry["value_to"],
67) 							}
68) 						)
69) 					);
70) 				}
71) 			);
72) 			process.exit(0);
73) 			break;
74) 		}
75) 		case "export":
76) 		{
77) 			const result : Array<any> = await services.concept.export_();
78) 			console.info(JSON.stringify(result, undefined, "\t"));
79) 			process.exit(0);
80) 			break;
81) 		}
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

82) 		case "search":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

83) 		{
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

84) 			const part : string = args.join(" "); args = [];
85) 			const result = await services.concept.search(part);
86) 			result.forEach
87) 			(
88) 				(entry) =>
89) 				{
90) 					console.info
91) 					(
92) 						helpers.string.coin
93) 						(
94) 							"{{id}} | {{type}} | {{description}} | {{tags}} | {{translations}}",
95) 							{
96) 								"id": entry["id"].toFixed(),
97) 								"type": entry["type"],
98) 								"description": (entry["description"] ?? '-'),
99) 								"tags": entry["tags"].join(","),
100) 								"translations": entry["translations"].map(foo => (foo["language"] + ":" + foo["value"])).join(","),
101) 							}
102) 						)
103) 					);
104) 				}
105) 			);
106) 			process.exit(0);
107) 			break;
108) 		}
109) 		case "feed":
110) 		{
111) 			const content : string = await helpers.misc.stdin();
112) 			const data : any = JSON.parse(content);
113) 			const concept_thing : any = data;
114) 			const concept_id : int = await services.concept.suck(concept_thing);
115) 			console.info(concept_id);
116) 			process.exit(0);
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

117) 			break;
118) 		}
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

119) 		case "new":
120) 		{
121) 			if (args.length < 1)
122) 			{
123) 				syntaxerror();
124) 			}
125) 			else
126) 			{
127) 				const type : string = args.shift();
128) 				const tags : Array<string> = (
129) 					(args.length >= 1)
130) 					? args.shift().split(",")
131) 					: []
132) 				);
133) 				const description : string = (
134) 					(args.length >= 1)
135) 					? args.shift()
136) 					: null
137) 				);
138) 				const concept_thing : any =
139) 				{
140) 					"type": type,
141) 					"description": description,
142) 					"tags": tags,
143) 					"translations": [],
144) 				};
145) 				const concept_id : int = await services.concept.suck(concept_thing);
146) 				console.info(concept_id);
147) 				process.exit(0);
148) 			}
149) 			break;
150) 		}
151) 		case "set":
152) 		{
153) 			if (args.length < 1)
154) 			{
155) 				syntaxerror();
156) 			}
157) 			else
158) 			{
159) 				const concept_id : int = parseInt(args.shift());
160) 			}
161) 		}