From 2b77e325ae7305cfc2a072fea495e2dd3ea223b4 Mon Sep 17 00:00:00 2001 From: Jon-William Lewis Date: Mon, 15 Feb 2016 00:40:36 -0600 Subject: [PATCH] Changed old argument parser to more sensible case statement; began work to recognize any path as a valid note path. --- src/main/stage2.sns.sh | 90 ++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/src/main/stage2.sns.sh b/src/main/stage2.sns.sh index 10cbc02..3ddb324 100644 --- a/src/main/stage2.sns.sh +++ b/src/main/stage2.sns.sh @@ -1,35 +1,57 @@ - #============================================================================== - # Stage 2: Argument Parsing - #============================================================================== - NAME="" - NOTEBOOK="" - SECTION="" - if [ -z "$1" ]; then help; exit 20 - else - ARGS=( "$@" ) - for ARG in "${ARGS[@]}"; do - if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE" - elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" - elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" - elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 - elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then init_store; exit 0 - else - if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" - elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" - elif [ -z "$SECTION" ] && [ -n "$ARG" ]; then SECTION="$ARG" - fi - fi - done - if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then - # If a note title was specified, but no notebook, and the list option - # was specified, assume that the detected note title is actually the - # name of a notebook - NOTEBOOK="$NAME" - NAME="" - fi - fi +#============================================================================== +# Stage 2: Argument Parsing +#============================================================================== +NOTE="" +if [ -z "$1" ]; then help; exit 20 +else +for ARG in "$@"; do + case "$ARG" in + -c|--create) + CREATE="TRUE" + OP="TRUE" + ;; + -d|--delete) + DELETE="TRUE" + OP="TRUE" + ;; + -e|--edit) + EDIT="TRUE" + OP="TRUE" + ;; + -ce|-ec) + CREATE="TRUE" + EDIT="TRUE" + OP="TRUE" + ;; + -l|--list) + LIST="TRUE" + OP="TRUE" + ;; + -p|--print) + PRINT="TRUE" + OP="TRUE" + ;; + -h|--help) + help + exit 0 + ;; + -i|--init-store) + init_store + exit 0 + ;; + *) + NOTE="$ARG" + break; + ;; + esac +done +if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then + # If a note title was specified, but no notebook, and the list option + # was specified, assume that the detected note title is actually the + # name of a notebook + NOTEBOOK="$NAME" + NAME="" +fi +fi - # w_conf and help are called here to avoid excess stage 3 code. +# w_conf and help are called here to avoid excess stage 3 code.