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 


#!/bin/sh
 
db_create() {
	mkdir ./"$1" && mkdir "./$1/.tag" && echo "Create DB \`$1'"
}
 
db_delete() {
	rm -r ./"$1" && echo "Delete DB \`$1'"
}
 
db_show() {
	if [ -z "$2" ]; then show_help; fi
	for x in "./$1/$2/"*; do
		echo "$x:" | sed "s/.*\///"
		cat "$x" | sed "s/^/    /"
		echo
	done
 
	printf "Tags: "
	ls "./$1/$2/.tag"
}
 
db_tag() {
	local db="$1" item="$2"
	shift
	shift
	for tag in $@; do
		mkdir "./$db/.tag/$tag"
		ln -s "$PWD/$db/$item" "./$db/.tag/$tag/"
		touch "./$db/$item/.tag/$tag"
	done
}
 
show_help() {
	echo "Usage: $0 command [args]"
	echo "Commands:"
	cat $0 | grep ") ##" | grep -v grep | sed 's/) ## /:\t/'
	exit
}
 
if [ -z "$1" ]; then show_help; fi
 
action=$1 it=database
shift
case $action in
	create) ## db -- create $it
		db_create "$@" ;;
 
	drop) ## db -- delete $it
		db_delete "$@" ;;
 
	add) ## db item -- add new item to $it
		mkdir -p "./$1/$2/.tag" && touch "./$1/$2/Description" ;;
 
	rem) ## db item -- delete item from $it
		rm -r "./$1/$2"
		rm "./$1/.tag/"*"/$2"
		;;
 
	show) ## db item -- show item
		db_show "$@" ;;
 
	newtag) ## db new-tag-name -- create new tag name
		mkdir "./$1/.tag/$2" ;;
 
	prop) ## db item property-name property-content -- add property to item
		echo "$4" > "./$1/$2/$3" ;;
 
	tag) ## db item tag [more-tags...] -- mark item with tags
		db_tag "$@" ;;
 
	last) ## db -- show latest item
		ls "$1" --sort=time | tail -n 1
		;;
 
	list) ## db -- list all items
		ls "$1" -1 --sort=time
		;;
 
	last-all) ## db -- list items in each category
		for x in "$1/.tag/"*; do
			echo "$x" | sed 's/.*\//Tag: /'
			printf "    "
			ls "$x" --sort=time | tail -n 1
			echo
		done
		;;
 
	help) ## this message
		show_help
		;;
 
	*)	echo Bad DB command: $1
		show_help
		;;
esac