From 498a7f0a83b701a74d0bb4b782b01aa147572321 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 21 Sep 2015 23:25:37 -0700 Subject: [PATCH] 0.2.0. See CHANGELOG.md --- CHANGELOG.md | 13 +++++++++++++ README.md | 2 +- jsonlite | 52 +++++++++++++++++++++++++++++++++------------------- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4df475..cac61b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,15 @@ CHANGELOG ========= + +## 0.2.0 - *9/21/2015* + +- `get` and `delete` are now idempotent. For example, if you call `get` and pass a uuid that doesn't exist, no error status code is returned. Instead a **0** status code is returned and nothing is written to `stdout`. + +- Now validates document id arguments passed into `get` and `delete` via regex. If invalid, a return status code of **3** is returned. + +- Return status codes changed and standardized. + 0 => Success + 1 => Missing required argument json document + 2 => Missing required argument document id + 3 => Invalid argument document id + 4 => Failure confirming destroy diff --git a/README.md b/README.md index 26a3a0c..fa00b6f 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Are you sure you want to destroy '/jsonlite.data' (y/n)? y ```` ➜ jsonlite version -0.1.0 +0.2.0 ```` ## Changelog diff --git a/jsonlite b/jsonlite index 2d7c945..f038b21 100755 --- a/jsonlite +++ b/jsonlite @@ -2,10 +2,18 @@ set -e -VERSION="0.1.0" +VERSION="0.2.0" COMMAND=$1 CWD=$(pwd); +function is_valid_uuid { + if [[ $1 =~ [A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$ ]]; then + echo true + fi + + echo false +} + case "$COMMAND" in "set") @@ -32,16 +40,18 @@ case "$COMMAND" in if [ -z "$2" ]; then printf "Missing required argument document id" - exit 1; + exit 2; fi - if [ ! -f "$CWD/jsonlite.data/$2" ]; then - printf "Document id '%s' not found in '$CWD/jsonlite.data'" "$2" - exit 1; + VALID=$(is_valid_uuid "$2") + if [ "$VALID" = false ]; then + printf "Invalid argument document id" + exit 3; fi - # Need to guard against passing naughty things such as ../.. - cat "$CWD/jsonlite.data/$2" + if [ -f "$CWD/jsonlite.data/$2" ]; then + cat "$CWD/jsonlite.data/$2" + fi ;; @@ -49,27 +59,31 @@ case "$COMMAND" in if [ -z "$2" ]; then printf "Missing required argument document id" - exit 1; + exit 2; fi - if [ ! -f "$CWD/jsonlite.data/$2" ]; then - printf "Document id '%s' not found in '$CWD/jsonlite.data'" "$2" - exit 1; + VALID=$(is_valid_uuid "$2") + if [ "$VALID" = false ]; then + printf "Invalid argument document id" + exit 3; fi - # Need to guard against passing naughty things such as ../.. - rm -f "$CWD/jsonlite.data/$2" + if [ -f "$CWD/jsonlite.data/$2" ]; then + rm -f "$CWD/jsonlite.data/$2" + fi ;; "destroy") - read -p "Are you sure you want to destroy '$CWD/jsonlite.data' (y/n)? " confirm - case "$confirm" in - # Need to guard against potential naughty things - y|Y|yes|YES ) rm -rf "$CWD/jsonlite.data";; - * ) exit 1;; - esac + if [ -d "$CWD/jsonlite.data" ]; then + read -p "Are you sure you want to destroy '$CWD/jsonlite.data' (y/n)? " confirm + case "$confirm" in + # Need to guard against potentially naughty things + y|Y|yes|YES ) rm -rf "$CWD/jsonlite.data";; + * ) exit 4;; + esac + fi ;;