diff --git a/utils/ldspk.sh b/utils/ldspk.sh index b06509735d02563334c918caf8a26a3fd52ca00b..f50c1c2113e27819397de8a46b9d810d71b713d0 100755 --- a/utils/ldspk.sh +++ b/utils/ldspk.sh @@ -1,17 +1,23 @@ #!/bin/bash +# +# https://github.com/alangrafu/lodspeakr/blob/master/utils/ldspk.sh -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" USAGE="Usage: $0 create|delete uri|class|service foo [html|rdf|ttl|nt|json]" -formats=( html rdf ttl nt json all ) +if [[ $# -eq 0 || "$1" == "--help" ]]; then + echo $USAGE + exit 1 +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" operations=( create delete ) modules=( class service uri ) +formats=( html rdf ttl nt json all ) currentOperation= -currentFormat= currentModule= +currentFormat= -if [[ ${operations[@]} =~ $1 ]] -then +if [[ ${operations[@]} =~ $1 ]]; then currentOperation=$1 else echo "Operation \"$1\" not valid" @@ -19,8 +25,7 @@ else exit 1 fi -if [[ ${modules[@]} =~ $2 ]] -then +if [[ ${modules[@]} =~ $2 ]]; then currentModule=$2 else echo "Module \"$2\" not valid" @@ -28,31 +33,23 @@ else exit 1 fi -if [[ ${formats[@]} =~ $4 ]] -then +currentUnit=$3 + +if [[ ${formats[@]} =~ $4 ]]; then currentFormat=$4 else - if [ -z "$4" ] - then + if [ -z "$4" ]; then currentFormat="all" else echo "Format \"$4\" not valid" - echo $USAGE + echo $USAGE exit 1 fi fi - -currentUnit=$3 - - -if [[ $currentOperation == "create" ]] -then +if [[ $currentOperation == "create" ]]; then $DIR/modules/create-$currentModule.sh "$currentUnit" "$currentFormat" fi -if [[ $currentOperation == "delete" ]] -then +if [[ $currentOperation == "delete" ]]; then $DIR/modules/delete-$currentModule.sh "$currentUnit" "$currentFormat" fi - -