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 # Stage 2: Argument Parsing
#============================================================================== #==============================================================================
NAME="" NOTE=""
NOTEBOOK="" if [ -z "$1" ]; then help; exit 20
SECTION="" else
if [ -z "$1" ]; then help; exit 20 for ARG in "$@"; do
else case "$ARG" in
ARGS=( "$@" ) -c|--create)
for ARG in "${ARGS[@]}"; do CREATE="TRUE"
if [ "$ARG" = "-c" ] || [ "$ARG" = "--create" ]; then CREATE="TRUE"; OP="TRUE" OP="TRUE"
elif [ "$ARG" = "-d" ] || [ "$ARG" = "--delete" ]; then DELETE="TRUE"; OP="TRUE" ;;
elif [ "$ARG" = "-e" ] || [ "$ARG" = "--edit" ]; then EDIT="TRUE"; OP="TRUE" -d|--delete)
elif [ "$ARG" = "-ce" ] || [ "$ARG" = "-ec" ]; then EDIT="TRUE"; CREATE="TRUE"; OP="TRUE" DELETE="TRUE"
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"; OP="TRUE" OP="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"; OP="TRUE" ;;
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0 -e|--edit)
elif [ "$ARG" = "-i" ] || [ "$ARG" == "--init" ]; then init_store; exit 0 EDIT="TRUE"
else OP="TRUE"
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG" ;;
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG" -ce|-ec)
elif [ -z "$SECTION" ] && [ -n "$ARG" ]; then SECTION="$ARG" CREATE="TRUE"
fi EDIT="TRUE"
fi OP="TRUE"
done ;;
if [ -n "$NAME" ] && [ -z "$NOTEBOOK" ] && [ -n "$LIST" ]; then -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 # If a note title was specified, but no notebook, and the list option
# was specified, assume that the detected note title is actually the # was specified, assume that the detected note title is actually the
# name of a notebook # name of a notebook
NOTEBOOK="$NAME" NOTEBOOK="$NAME"
NAME="" NAME=""
fi fi
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.