CLI interface to medialist (fossil mirror)
Révision | f2f1d3a17c9e31ff289e47ae3516b5057f9107ac (tree) |
---|---|
l'heure | 2022-01-25 10:19:23 |
Auteur | mio <stigma@disr...> |
Commiter | mio |
change error handling for ml_fetch_* functions.
FossilOrigin-Name: f02e7ff73665b75e1a87f98c34b9c1c8a0a4eee3452e996afca4b684c385645e
@@ -43,6 +43,7 @@ struct MediaListItem | ||
43 | 43 | string startDate; |
44 | 44 | string endDate; |
45 | 45 | string lastUpdated; |
46 | + bool valid = false; | |
46 | 47 | } |
47 | 48 | |
48 | 49 | struct MediaListHeader |
@@ -187,10 +188,16 @@ MediaListHeader[] ml_fetch_headers(MediaList* list) | ||
187 | 188 | return headers; |
188 | 189 | } |
189 | 190 | |
190 | -MLError ml_fetch_item(MediaList* list, size_t id, MediaListItem* item) | |
191 | +MediaListItem ml_fetch_item(MediaList* list, size_t id, MLError* err = null) | |
191 | 192 | { |
192 | - if (true == list.isOpen) | |
193 | - return MLError.fileAlreadyOpen; | |
193 | + MediaListItem newItem; | |
194 | + | |
195 | + if (true == list.isOpen) { | |
196 | + if (null !is err) | |
197 | + *err = MLError.fileAlreadyOpen; | |
198 | + | |
199 | + return newItem; | |
200 | + } | |
194 | 201 | |
195 | 202 | list.isOpen = true; |
196 | 203 |
@@ -214,8 +221,12 @@ MLError ml_fetch_item(MediaList* list, size_t id, MediaListItem* item) | ||
214 | 221 | currentLine += 1; |
215 | 222 | } |
216 | 223 | |
217 | - if (false == found) | |
218 | - return MLError.itemNotFound; | |
224 | + if (false == found) { | |
225 | + if (null !is err) | |
226 | + *err = MLError.itemNotFound; | |
227 | + | |
228 | + return newItem; | |
229 | + } | |
219 | 230 | |
220 | 231 | int[2][6] headerPositions = _ml_get_header_positions(list); |
221 | 232 |
@@ -252,21 +263,27 @@ MLError ml_fetch_item(MediaList* list, size_t id, MediaListItem* item) | ||
252 | 263 | } |
253 | 264 | } |
254 | 265 | |
255 | - MediaListItem newItem = MediaListItem(sections[titleIndex], | |
256 | - sections[progressIndex], sections[statusIndex], sections[startIndex], | |
257 | - sections[endIndex], sections[lastIndex]); | |
258 | - | |
259 | - *item = newItem; | |
266 | + newItem.title = sections[titleIndex]; | |
267 | + newItem.progress = sections[progressIndex]; | |
268 | + newItem.status = sections[statusIndex]; | |
269 | + newItem.startDate = sections[startIndex]; | |
270 | + newItem.endDate = sections[endIndex]; | |
271 | + newItem.lastUpdated = sections[lastIndex]; | |
272 | + newItem.valid = true; | |
260 | 273 | |
261 | 274 | list.isOpen = false; |
262 | 275 | |
263 | - return MLError.success; | |
276 | + return newItem; | |
264 | 277 | } |
265 | 278 | |
266 | -MediaListItem[] ml_fetch_items(MediaList* list, size_t[] ids ...) | |
279 | +MediaListItem[] ml_fetch_items(MediaList* list, MLError* err, size_t[] ids ...) | |
267 | 280 | { |
268 | - if (list.isOpen) | |
281 | + if (list.isOpen) { | |
282 | + if (null !is err) | |
283 | + *err = MLError.fileAlreadyOpen; | |
284 | + | |
269 | 285 | return null; |
286 | + } | |
270 | 287 | |
271 | 288 | File listFile = File(list.filePath); |
272 | 289 | list.isOpen = true; |
@@ -325,7 +342,7 @@ MediaListItem[] ml_fetch_items(MediaList* list, size_t[] ids ...) | ||
325 | 342 | string[] sections = line.strip().split("\t"); |
326 | 343 | items ~= MediaListItem(sections[titleIndex], |
327 | 344 | sections[progressIndex], sections[statusIndex], sections[startIndex], |
328 | - sections[endIndex], sections[lastIndex]); | |
345 | + sections[endIndex], sections[lastIndex], true); | |
329 | 346 | } |
330 | 347 | |
331 | 348 | currentID += 1; |
@@ -334,10 +351,14 @@ MediaListItem[] ml_fetch_items(MediaList* list, size_t[] ids ...) | ||
334 | 351 | return items; |
335 | 352 | } |
336 | 353 | |
337 | -MediaListItem[] ml_fetch_all(MediaList* list) | |
354 | +MediaListItem[] ml_fetch_all(MediaList* list, MLError* err = null) | |
338 | 355 | { |
339 | - if (list.isOpen) | |
356 | + if (list.isOpen) { | |
357 | + if (null !is err) | |
358 | + *err = MLError.fileAlreadyOpen; | |
359 | + | |
340 | 360 | return null; |
361 | + } | |
341 | 362 | |
342 | 363 | File listFile = File(list.filePath); |
343 | 364 | list.isOpen = true; |
@@ -395,7 +416,7 @@ MediaListItem[] ml_fetch_all(MediaList* list) | ||
395 | 416 | |
396 | 417 | items ~= MediaListItem(sections[titleIndex], |
397 | 418 | sections[progressIndex], sections[statusIndex], sections[startIndex], |
398 | - sections[endIndex], sections[lastIndex]); | |
419 | + sections[endIndex], sections[lastIndex], true); | |
399 | 420 | } |
400 | 421 | |
401 | 422 | list.isOpen = false; |