Changed old argument parser to more sensible case statement; began work to recognize

any path as a valid note path.
This commit is contained in:
Jon-William Lewis
2016-02-15 00:40:36 -06:00
parent d11c2597c4
commit 2b77e325ae

View File

@@ -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.