• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

CLI interface to medialist (fossil mirror)


Commit MetaInfo

Revisión835bc64301fa36da0feb02c20aba4f514691293a (tree)
Tiempo2023-03-30 13:05:32
Autormio <stigma@disr...>
Commitermio

Log Message

Update documentation for 0.4 release. Still some work to do.

FossilOrigin-Name: 117419016d47681a3d300e0537450fd80d34f281bd09d2d1572414cf13835f4f

Cambiar Resumen

Diferencia incremental

--- a/docs/medialist.info
+++ b/docs/medialist.info
@@ -95,25 +95,35 @@ fields (if any), and what their purpose is.
9595
9696 The first (and most important) structure is the @samp{MediaList} structure.
9797 This structure is passed to all functions that are defined in this package.
98+
99+It is recommended to create an instance by using the @code{ml_open_list}
100+function.
101+
98102 It has the following members:
99103
100104 @table @samp
101105 @item immutable string filePath
102-The absolute file path to the @dfn{TSV} file. Upon creating a @samp{MediaList}
103-structure, a check is performed to see if this file exists. If not, it is
104-created.
106+The absolute file path to the @dfn{TSV} file. Upon creating a
107+@samp{MediaList} structure, a check is performed to see if this file exists.
108+If it doesn't exist, it is created.
105109
106110 @item immutable string listName
107-The name of the ``list''. This is determined by extracting the file name from
108-the @samp{filePath}. For example, a @samp{filePath} of
109-@code{/home/user/lists/mylist.tsv} would have the @samp{listName} of
111+The name of the ``list''. This is determined by extracting the file name
112+from the @samp{filePath}. For example, if the @samp{filePath} is
113+@code{/home/user/lists/mylist.tsv}, then the @samp{listName} would be
110114 @samp{mylist}.
111115
112116 @item bool isOpen
113117 A check to see if the file at @samp{filePath} is open. All of the functions
114118 which edit the file will check this before doing anything. By providing
115-public access to this, I hope people can make their own functions to suit there
116-needs without breaking any of the ones provided in this package.
119+public access to this, I hope people can make their own functions to suit
120+there needs without breaking any of the ones provided in this package.
121+
122+@cartouche
123+@strong{NOTE:} The future of this property is being evaluated. It requires
124+people using this library to remember that it exists, and performing checks
125+on its value. It is probable that this will be removed in a future version.
126+@end cartouche
117127 @end table
118128
119129 @section MediaListHeader
@@ -121,8 +131,8 @@ needs without breaking any of the ones provided in this package.
121131 @pindex struct MediaListHeader
122132
123133 Contains information about a particular ``header'' (i.e. column) in the
124-@dfn{TSV} file. Editing these values
125-@emph{does not change their values in the list}.
134+@dfn{mTSV} file. Editing these values @emph{does not change their values
135+in the list}.
126136
127137 @table @samp
128138 @item string tsvName
@@ -130,6 +140,8 @@ The literal column name as written in the @dfn{TSV} file.
130140
131141 @item string humanFriendlyName
132142 The ``human friendly name'' as determined by the comments (@pxref{mTSV}).
143+If this value is set, then it should be used when displaying the header
144+to people. The default value is @code{null}.
133145
134146 @item size_t column
135147 The column number that this header is for. Useful if you want to read from
@@ -150,21 +162,24 @@ these values @emph{does not change their values in the list}.
150162 The title of this item in the list.
151163
152164 @item string progress
153-The current progress of this item in the list. By default this is @samp{-/-}.
165+The current progress of this item in the list. By default this is
166+@samp{-/-}.
154167
155168 @item string status
156-The current status of this item in the list. By default this is @samp{UNKNOWN}.
169+The current status of this item in the list. By default this is
170+@samp{UNKNOWN}.
157171
158172 @item string startDate
159173 The date that this item was ``started'' on. The format for this is
160-@samp{YYYY-MM-DD}. This value is automatically updated when the @samp{status}
161-changes from @samp{PLAN-TO-READ} or @samp{PLAN-TO-WATCH} to @samp{READING} or
162-@samp{WATCHING} respectively.
174+@samp{YYYY-MM-DD}. This value is automatically updated when the
175+@samp{status} changes from @samp{PLAN-TO-READ} or @samp{PLAN-TO-WATCH} to
176+@samp{READING} or @samp{WATCHING} respectively.
163177
164178 @item string endDate
165179 The date that this item was ``completed'' on. The format for this is
166-@samp{YYYY-MM-DD}. This value is automatically updated when the @samp{status}
167-changes from @samp{READING} or @samp{WATCHING} to @samp{COMPLETE}.
180+@samp{YYYY-MM-DD}. This value is automatically updated when the
181+@samp{status} changes from @samp{READING} or @samp{WATCHING} to
182+@samp{COMPLETE}.
168183
169184 @item string lastUpdated
170185 The date that this item was last updated on. The format for this is
@@ -175,21 +190,42 @@ is updated.
175190 A check to see if this item was initialized correctly upon being fetched.
176191 If it is @code{false}, then it failed and the values shouldn't be trusted.
177192
193+@cartouche
194+@strong{NOTE}: The future of this property is undecided. It requires that
195+programmers remeber it exists, and to make use of it. With MediaList 0.4,
196+most functions throw an exception (@xref{x-mlexception,,MLException}) if
197+there is an error, or return an error type (@xref{x-mlerror,,MLError}) when
198+an error occurs a ``nothrow'' variant of a function has been called.
199+@end cartouche
200+
201+@item string tsvRepresentation()
202+
203+This member function will convert a @samp{MediaListItem} structure in to a
204+TSV representation. This does @strong{not} add a trailing newline
205+character. The order follows the MediaList default order:
206+
207+@verbatim
208+title, progress, status, start_date, end_date, last_updated
209+@end verbatim
210+
178211 @end table
179212
180-@section MLCommand
181213 @anchor{x-mlcommand}
214+@section MLCommand
182215
183216 @pindex enum MLCommand
184217
218+This enumeration type represents the type of command when sending a list of
219+arguments to @code{ml_send_command} when updating a @samp{MediaList}.
220+
185221 @table @code
186222
187223 @item add
188224 @pindex MLCommand.add
189225
190-By providing the ``add'' command to @code{ml_send_command}, you are indicating
191-that you want to append a new item to the list. The format of the arguments
192-(@var{string[] args}) is as follows:
226+By providing the ``add'' command to @code{ml_send_command}, you are
227+indicating that you want to append a new item to the list. The format of the
228+arguments (@var{string[] args}) is as follows:
193229
194230 @verbatim
195231 args[0] = The new item's Title
@@ -203,24 +239,21 @@ defaults (``-/-'' for Progress and ``UNKNOWN'' for Status).
203239 @item delete_
204240 @pindex MLCommand.delete_
205241
206-Sending the ``delete'' command a list can have multiple meanings, depending
207-on the arguments provided. If you provide no arguments, then the entire list
208-is deleted. If at least one arugment is provided, then only the provided
209-arguments are deleted.
210-
211-For example, to delete an entire list:
212-
213-@example
214-ml_send_command(list, MLCommand.delete_, []);
215-@end example
216-
217-To delete specific items from a list:
242+By sending the ``delete_'' command to a list, you're saying that each item
243+ID in the provided arguments should be removed from the list. For example:
218244
219245 @example
220246 ml_send_command(list, MLCommand.delete_, ["1", "10", "3"]);
221247 @end example
222248
223-Each of the items represents the item ID. The need not be in order.
249+The order of the IDs does not matter, this will remove the items with IDs 1,
250+3, and 10.
251+
252+@cartouche
253+@strong{NOTE}: Previously you could send an empty array as an argument to
254+delete the list file. This behaviour is deprecated and will be removed in
255+a future version.
256+@end cartouche
224257
225258 @item update
226259 @pindex MLCommand.update
@@ -234,7 +267,9 @@ args[0] = Item ID (e.g. "1").
234267 args[n] = field::value
235268 @end verbatim
236269
237-The possible values for "field" are:
270+The double colons (@samp{::}) acts as a separator.
271+
272+The possible values for ``field'' are:
238273
239274 @itemize @bullet
240275 @item title
@@ -244,10 +279,11 @@ The possible values for "field" are:
244279 @item end_date
245280 @end itemize
246281
247-The "value" can include whitespace.
282+The ``value'' can contain spaces.
248283
249284 @end table
250285
286+@anchor{x-mlerror}
251287 @section MLError
252288
253289 @pindex enum MLError
@@ -258,13 +294,14 @@ The "value" can include whitespace.
258294 @pindex MLError.success
259295
260296 This value indicates that the function worked without any errors. You can
261-proceed as normal.
297+proceed as normal. The value of @samp{success} is 0.
262298
263299 @item invalidArgs
264300 @pindex MLError.invalidArgs
265301
266302 This value indicates that the arguments provided weren't sufficient. For
267-example, sending an empty array with the @code{MLCommand.add} command.
303+example, sending an empty array with the @code{MLCommand.add} command. The
304+value of @samp{invalidArgs} is 1.
268305
269306 @item fileAlreadyOpen
270307 @pindex MLError.fileAlreadyOpen
@@ -272,23 +309,79 @@ example, sending an empty array with the @code{MLCommand.add} command.
272309 This error is returned when a @code{MediaList} structure is in an ``open''
273310 state. All the functions provided in this package check the file isn't
274311 open before reading/writing. Should you choose to extend this package
275-by writing your own functions, this can prevent accidental read/write errors.
312+by writing your own functions, this can prevent accidental read/write
313+errors. The value of @samp{fileAlreadyOpen} is 2.
276314
277315 @item fileReadError
278316 @pindex MLError.fileReadError
279317
280-An error was encountered when reading the list file.
318+An error was encountered when reading the list file. The value for
319+@samp{fileReadError} is 3.
281320
282321 @item itemNotFound
283322 @pindex MLError.itemNotFound
284323
285-A requested item (either @code{ml_fetch_item} or @code{ml_fetch_items}) could
286-not be found.
324+A requested item (by @code{ml_fetch_item} or @code{ml_fetch_items}) could
325+not be found. The value of @samp{itemNotFound} is 4.
326+
327+@item permissionError
328+@pindex MLError.permissionError
329+
330+When trying to create or open the file for a @code{MediaList}, we
331+encountered a permission error and couldn't open the file. The value for
332+@samp{permissionError} is 5.
287333
288334 @item unknownCommand
289335 @pindex MLError.unknownCommand
290336
291-An unknown command was provided to @code{ml_send_command}.
337+An unknown command was provided to the @var{command} parameter for the
338+@code{ml_send_command} function. The value of @samp{unknownCommand} is 6.
339+
340+@item unspecifiedError
341+@pindex MLError.unspecifiedError
342+
343+An unknown error occurred. This is used as a fallback for operating system
344+and Phobos exceptions. The value of @samp{unspecifiedError} is always
345+equal to @code{MLError.max}.
346+
347+@end table
348+
349+@anchor{x-mlexception}
350+@section MLException
351+
352+@pindex class MLException
353+
354+A custom MediaList Exception class which is used for error reporting in
355+the functions which throw (rather than the @code{nothrow} variants).
356+
357+@table @code
358+
359+@item MLError error()
360+@pindex MLException.error
361+
362+Returns the underlying @code{MLError} value.
363+
364+@item string msg()
365+@pindex MLException.msg
366+
367+Return a string describing the reason for the exception.
368+
369+@item this(string msg)
370+@pindex MLException.this(string msg)
371+
372+Construct a new @code{MLException} by providing only an error message.
373+
374+@item this(MLError error)
375+@pindex MLException.this(MLError error)
376+
377+Construct a new @code{MLException} by providing a @code{MLError} code. The
378+error message is determined by this value.
379+
380+@item this(string msg, MLError error)
381+@pindex MLException.this(string msg, MLError error)
382+
383+Construct a new @code{MLException} by providing a custom message and error
384+code.
292385
293386 @end table
294387
@@ -343,26 +436,28 @@ The format of @var{args} depends on what the @var{command} is.
343436 A simple example that demonstrates most aspects of the library.
344437
345438
346-@verbatim
347-// I (mio, <stigma@disroot.org>) have release this example to the
439+@example
440+// I (mio, <stigma@@disroot.org>) have released this example to the
348441 // public domain. For more information, visit
349442 // <http://creativecommons.org/publicdomain/zero/1.0/>.
350-import std.stdio;
443+
444+import std.stdio : stderr, writeln, writefln;
445+import std.file : remove;
351446
352447 import medialist;
353448
354449 void print_error(MLError err)
355-{
356- writefln("Error: MLError.%s", err);
357-}
450+@{
451+ stderr.writefln("Error: MLError.%s", err);
452+@}
358453
359454 int main(string[] args)
360-{
455+@{
361456 if (2 > args.length)
362- {
457+ @{
363458 stderr.writefln("usage: %s <path_to_list.tsv>", args[0]);
364459 return 1;
365- }
460+ @}
366461
367462 /* Open a new list for editing, creating the file if needed */
368463 MediaList* list = ml_open_list(args[1]);
@@ -370,6 +465,9 @@ int main(string[] args)
370465 /* Make sure the memory is returned when the program exits. */
371466 scope(exit) ml_free_list(list);
372467
468+ /* Since we don't want to keep the file for this example. */
469+ scope(exit) remove(list.filePath);
470+
373471 /* Error handling */
374472 MLError err;
375473
@@ -380,18 +478,18 @@ int main(string[] args)
380478 * The second has default status (UNKNOWN).
381479 * The third has default progress (-/-).
382480 */
383- err = ml_send_command(list, MLCommand.add, ["Item 1"]);
481+ ml_send_command(list, MLCommand.add, ["Item 1"], err);
384482 if (MLError.success != err) print_error(err);
385483
386- err = ml_send_command(list, MLCommand.add, ["Item 2", "10/100"]);
484+ ml_send_command(list, MLCommand.add, ["Item 2", "10/100"], err);
387485 if (MLError.success != err) print_error(err);
388486
389- err = ml_send_command(list, MLCommand.add,
390- ["Item 3", null, "PLAN-TO-WATCH"]);
487+ ml_send_command(list, MLCommand.add, ["Item 3", null, "PLAN-TO-WATCH"],
488+ err);
391489 if (MLError.success != err) print_error(err);
392490
393- err = ml_send_command(list, MLCommand.add,
394- ["Item 4", "10/10", "COMPLETE"]);
491+ ml_send_command(list, MLCommand.add, ["Item 4", "10/10", "COMPLETE"],
492+ err);
395493
396494
397495 /*
@@ -401,24 +499,24 @@ int main(string[] args)
401499 * We update the start date and end date of item 4.
402500 * We update the title of item 3.
403501 */
404- err = ml_send_command(list, MLCommand.update,
405- ["1", "progress::0/100", "status::PLAN-TO-READ"]);
502+ ml_send_command(list, MLCommand.update,
503+ ["1", "progress::0/100", "status::PLAN-TO-READ"], err);
406504 if (MLError.success != err) print_error(err);
407505
408- err = ml_send_command(list, MLCommand.update,
409- ["4", "start_date::2021-11-25",
410- "end_date::2022-02-13"]);
506+ ml_send_command(list, MLCommand.update,
507+ ["4", "start_date::2021-11-25", "end_date::2022-02-13"],
508+ err);
411509 if (MLError.success != err) print_error(err);
412510
413- err = ml_send_command(list, MLCommand.update,
414- ["3", "title::The Third Item"]);
511+ ml_send_command(list, MLCommand.update, ["3", "title::The Third Item"],
512+ err);
415513 if (MLError.success != err) print_error(err);
416514
417515 /* Fetch an item and write the details out. */
418- MediaListItem item4 = ml_fetch_item(list, 4, &err);
516+ MediaListItem item4 = ml_fetch_item(list, 4, err);
419517
420518 if (MLError.success == err && true == item4.valid)
421- {
519+ @{
422520 writeln("Details about item4:");
423521 writefln("Title: %s", item4.title);
424522 writefln("Progress: %s", item4.progress);
@@ -426,26 +524,23 @@ int main(string[] args)
426524 writefln("Start Date: %s", item4.startDate);
427525 writefln("End Date: %s", item4.endDate);
428526 writefln("Last Update: %s", item4.lastUpdated);
429- }
527+ @}
430528 else
431- {
529+ @{
432530 stderr.writefln("Failed to fetch item4: MLError.%s (Valid? %s)",
433531 err, item4.valid ? "true" : "false");
434- }
532+ @}
435533
436534 /*
437- * Delete some items, then delete the list file.
535+ * Delete some items.
438536 */
439- err = ml_send_command(list, MLCommand.delete_, ["3", "2"]);
440- if (MLError.success != err) print_error(err);
441-
442- err = ml_send_command(list, MLCommand.delete_, []);
537+ ml_send_command(list, MLCommand.delete_, ["3", "2"], err);
443538 if (MLError.success != err) print_error(err);
444539
445540 /* Done ! */
446541 return 0;
447-}
448-@end verbatim
542+@}
543+@end example
449544
450545
451546 @node Index
--- a/medialist.d
+++ b/medialist.d
@@ -141,9 +141,6 @@ struct MediaListItem
141141 ///
142142 /// title, progress, status, start_date, end_date, last_updated.
143143 ///
144- /// Params:
145- /// item = The MediaListItem to convert to a string
146- ///
147144 /// Returns: A string containing the TSV representation of *item*.
148145 ///
149146 string tsvRepresentation() const {
@@ -222,7 +219,7 @@ enum MLCommand
222219 ///
223220 /// If no there are no "Item ID" values in `args`, then the entire
224221 /// list is irreversibly deleted. **NOTE**: This functionality has
225- /// been deprecated from version 0.2.0, it'll be removed in a later
222+ /// been deprecated from version 0.4, it'll be removed in a later
226223 /// version.
227224 ///
228225 delete_,
@@ -263,12 +260,12 @@ enum MLError
263260 itemNotFound,
264261 /// We don't have permission to edit the list file.
265262 permissionError,
266- /// Unknown error has occurred.
267- unspecifiedError,
268263 /// Unknown value sent to ml_send_command.
269264 ///
270265 /// Check all values in the `MLCommand` enumeration.
271266 unknownCommand,
267+ /// Unknown error has occurred.
268+ unspecifiedError,
272269 }
273270
274271 private static string[] mlErrorStrings = [