Task

Write a simple tool to track a small set of data.

The tool should have a command-line interface to enter at least two different values.

The entered data should be stored in a structured format and saved to disk.

It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, baseball cards, books), a diary, an electronic organizer (birthdays/anniversaries/phone numbers/addresses), etc.



You should track the following details:

 A description of the item. (e.g., title, name)
 A category or tag (genre, topic, relationship such as “friend” or “family”)
 A date (either the date when the entry was made or some other date that is meaningful, like the birthday); the date may be generated or entered manually
 Other optional fields


The command should support the following Command-line arguments to run:

 Add a new entry
 Print the latest entry
 Print the latest entry for each category
 Print all entries sorted by a date


The category may be realized as a tag or as structure (by making all entries in that category subitems)

The file format on disk should be human readable, but it need not be standardized.   A natively available format that doesn't need an external library is preferred.   Avoid developing your own format if you can use an already existing one.   If there is no existing format available, pick one of:

   JSON
   S-Expressions
   YAML
   others


Related task

   Take notes on the command line 


HELP=: 0 :0
Commands:
 
DBNAME add DATA
DBNAME display the latest entry
DBNAME display the latest entry where CATEGORY contains WORD
DBNAME display all entries
DBNAME display all entries order by CATEGORY
 
1) The first add with new DBNAME assign category names.
2) lower case arguments verbatim.
3) UPPER CASE: substitute your values.
 
Examples, having saved this program as a file named s :
$ jconsole s simple.db display all entries
$ jconsole s simple.db add "first field" "2nd field"
)
 
Q=: ''''                                NB. quote character
time=: 6!:0@:('YYYY-MM-DD:hh:mm:ss.sss'"_)
 
embed=: >@:{.@:[ , ] , >@:{:@:[
assert '(x+y)' -: '()' embed 'x+y'
 
Duplicate=: 1 :'#~ m&= + 1 #~ #'
assert 0 1 2 3 3 4 -: 3 Duplicate i.5
 
prepare=: LF ,~ [: }:@:; (Q;Q,';')&embed@:(Q Duplicate)&.>@:(;~ time)
assert (-: }.@:".@:}:@:prepare) 'boxed';'';'li''st';'of';'''strings'''
 
categorize=: dyad define
i=. x i. y
if. (1 (~: #) i) +. i (= #) x do.
 smoutput 'choose 1 of'
 smoutput x
 exit 1
end.
{. i                                  NB. "index of" frame has rank 1.
)
assert 0 -: 'abc' categorize 'a'
 
loadsdb=: (<'time') (<0 0)} ".;._2@:(1!:1)
 
Dispatch=: conjunction define
help
:
commands=. y
command=. {. commands
x (u`help@.(command(i.~ ;:)n)) }.commands
)
 
NB. the long fork in show groups (": #~ (1 1 embed (1j1 }:@:# (1 #~ #))))
show=: smoutput@:(": #~ 1 1 embed 1j1 }:@:# 1 #~ #)
 
in=: +./@:E.
assert 'the'    in'quick brown fox jumps over the lazy dog'
assert 'the'-.@:in'QUICK BROWN FOX JUMPS OVER THE LAZY DOG'
 
where=: dyad define
'category contains word'=. 3 {. y
if. 'contains' -.@:-: contains do.
 help''
 exit 1
end.
i=. x ({.@:[ categorize <@:]) category
j=. {: I. ; word&in&.> i {"1 x
if. 0 (= #) j do.
 smoutput 'no matches'
else.
 x (show@:{~ 0&,) j
end.
)
 
entry=: 4 : 0
if. a: = y do.
 show@:({. ,: {:) x
else.
 x ''`where Dispatch'where' y
end.
)
 
latest=: ''`entry Dispatch'entry'
the=: ''`latest Dispatch'latest'
 
by=: 4 : 0
i=. x (categorize~ {.)~ y
show ({. , (/: i&{"1)@:}.) x
)
 
order=: ''`by Dispatch'by'
 
entries=: 4 : 0
if. a: = y do.
 show x
else.
 x ''`order Dispatch'order' y
end.
)
 
all=: ''`entries Dispatch'entries'
 
help=: smoutput@:(HELP"_)
add=: 1!:3~ prepare                     NB. minimal---no error tests
display=: (the`all Dispatch'the all'~ loadsdb)~  NB. load the simple db for some sort of display
 
({. add`display Dispatch'add display' }.)@:(2&}.)ARGV
 
exit 0
 