[mod] main
Christian Fraß

Christian Fraß commited on 2021-03-05 07:46:19
Zeige 1 geänderte Dateien mit 64 Einfügungen und 18 Löschungen.

... ...
@@ -144,7 +144,7 @@ async function main(args : Array<string>) : Promise<void>
144 144
 			process.exit(0);
145 145
 			break;
146 146
 		}
147
-		case "new":
147
+		case "add":
148 148
 		{
149 149
 			if (args.length < 1)
150 150
 			{
... ...
@@ -152,24 +152,70 @@ async function main(args : Array<string>) : Promise<void>
152 152
 			}
153 153
 			else
154 154
 			{
155
-				const type : string = args.shift();
156
-				const tags : Array<string> = (
157
-					(args.length >= 1)
158
-					? args.shift().split(",")
159
-					: []
160
-				);
161
-				const description : string = (
162
-					(args.length >= 1)
163
-					? args.shift()
164
-					: null
165
-				);
166
-				const concept_thing : any =
167
-				{
168
-					"type": type,
169
-					"description": description,
170
-					"tags": tags,
171
-					"expressions": [],
155
+				/*
156
+				SYNOPSIS
157
+					add <type> [-d <description>] [-t <tag>] [-t <tag>] … [-e <language>:<value>] [-e <language>:<value>] _
158
+				
159
+				OPTIONS
160
+					<type>
161
+					-d <description> | --description=<description>
162
+					-t <tag> | --tag=<tag>
163
+					-e <language>:<value> | --expression=<language>:<value>
164
+				 */
165
+				const concept_thing : {type ?: string; description : null|string; tags : Array<string>; expressions : {[language : string] : Array<string>};} = {
166
+					"type": undefined,
167
+					"description": null,
168
+					"tags": [],
169
+					"expressions": {},
172 170
 				};
171
+				let positional : {list : Array<string>; index : int;} = {
172
+					"list": ["type"],
173
+					"index": 0,
174
+				};
175
+				while (args.length > 0)
176
+				{
177
+					const arg : string = args.shift();
178
+					switch (arg)
179
+					{
180
+						case "-h":
181
+						{
182
+							console.info("add <type> [-d <description>] [-t <tag>] [-t <tag>] … [-e <language>:<value>] [-e <language>:<value>] _");
183
+							process.exit(0);
184
+							break;
185
+						}
186
+						case "-d":
187
+						{
188
+							concept_thing["description"] = args.shift();
189
+							break;
190
+						}
191
+						case "-t":
192
+						{
193
+							concept_thing["tags"].push(args.shift());
194
+							break;
195
+						}
196
+						case "-e":
197
+						{
198
+							const [language, value] : Array<string> = args.shift().split(":", 2);
199
+							if (! concept_thing["expressions"].hasOwnProperty(language)) {
200
+								concept_thing["expressions"][language] = [];
201
+							}
202
+							concept_thing["expressions"][language].push(value);
203
+							break;
204
+						}
205
+						default:
206
+						{
207
+							if (positional.index < positional.list.length) {
208
+								concept_thing[positional.list[positional.index]] = arg;
209
+								positional.index += 1;
210
+							}
211
+							else {
212
+								throw (new Error("unexpected: " + arg));
213
+							}
214
+							break;
215
+						}
216
+					}
217
+				}
218
+// console.info(helpers.json.encode_extended(concept_thing, true, 0));
173 219
 				const concept_id : int = await services.concept.suck(concept_thing);
174 220
 				console.info(concept_id);
175 221
 				process.exit(0);
176 222