major rework - dossier - console collection manager DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit e00bb1cb184f084d75e1c0a8f202b553a069ac81 DIR parent 8c7a95569085ede05744318afe3212f4900aca2c HTML Author: Solene Rapenne <solene@perso.pw> Date: Sat, 14 Jul 2018 22:14:46 +0200 major rework Diffstat: M cdb | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) --- DIR diff --git a/cdb b/cdb @@ -1,6 +1,6 @@ #!/bin/sh -REPO=/home/solene/dev/cbd/games/ +: ${REPO:=/home/solene/dev/cbd/games/} # displays the values of an identifier # $1 identifier @@ -37,6 +37,9 @@ delete() { if [ -f "${attribute}/${1}" ] then rm "${attribute}/${1}" + else + printf "%s is not in the library!\n" "$1" + exit 1 fi done exit 0 @@ -77,7 +80,7 @@ add_value() { shift 2 mkdir -p "$ATTRIBUTE" - printf '%s' "$VALUE" > "$ATTRIBUTE"/"${ID}" + printf '%s' "$VALUE" > "${ATTRIBUTE}/${ID}" done exit 0 } @@ -103,21 +106,24 @@ list() { usage() { printf '%s\n' \ "cdb help" \ - "cdb ls" \ - "cdb ls attribute" \ - "cdb identifier" \ - "cdb attributes" \ - "cdb search attribute value" \ + "cdb show [identifier]" \ + "cdb search [attribute [value]]" \ "cdb identifier attribute value" exit 0 } if [ "$1" = "rm" ] && [ "$#" -eq 2 ] ; then delete "$2" ; fi -if [ "$1" = "ls" ] && [ "$#" -eq 2 ] ; then list "$2" ; fi if [ "$1" = "help" ] ; then usage ; fi -if [ "$1" = "ls" ] ; then show_list ; fi + +# dealing with identifiers +if [ "$1" = "show" ] && [ "$#" -eq 1 ]; then show_list ; fi +if [ "$1" = "show" ] && [ "$#" -eq 2 ]; then show "$2" ; fi + +# dealing with attributes +if [ "$1" = "search" ] && [ "$#" -eq 1 ]; then show_attributes ; fi +if [ "$1" = "search" ] && [ "$#" -eq 2 ]; then list "$2" ; fi if [ "$1" = "search" ] && [ "$#" -eq 3 ]; then search_value "$2" "$3" ; fi -if [ "$1" = "attrs" ]; then show_attributes ; fi -if [ "$#" -ge 3 ]; then add_value $@ ; fi -if [ "$#" -eq 1 ]; then show "$1" ; fi + +if [ "$#" -ge 3 ]; then add_value "$@" ; fi + usage