Skip to content

Commit

Permalink
0.2.0. See CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nodesocket committed Sep 22, 2015
1 parent be8bf3b commit 498a7f0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 33 additions & 19 deletions jsonlite
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -32,44 +40,50 @@ 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

;;

"delete")

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

;;

Expand Down

0 comments on commit 498a7f0

Please sign in to comment.