45 lines
1.7 KiB
Bash
45 lines
1.7 KiB
Bash
#==============================================================================
|
|
# Section: Argument Parsing
|
|
#==============================================================================
|
|
|
|
NAME=""
|
|
NOTEBOOK=""
|
|
SECTION=""
|
|
|
|
if [ -z "$1" ]; then #If no input was given, print help
|
|
help
|
|
exit 20
|
|
else #Assume the user wants to do something.
|
|
ARGS=( "$@" )
|
|
for ARG in ${ARGS[@]};do
|
|
if [ "$ARG" = "-c" -o "$ARG" = "--create" ]; then CREATE="TRUE"
|
|
elif [ "$ARG" = "-d" -o "$ARG" = "--delete" ]; then DELETE="TRUE"
|
|
elif [ "$ARG" = "-e" -o "$ARG" = "--edit" ]; then EDIT="TRUE"
|
|
elif [ "$ARG" = "-ce" -o "$ARG" = "-ec" ]; then EDIT="TRUE";CREATE="TRUE"
|
|
elif [ "$ARG" = "-p" -o "$ARG" = "--print" ]; then PRINT="TRUE"
|
|
elif [ "$ARG" = "-l" -o "$ARG" = "--list" ]; then LIST="TRUE"
|
|
elif [ "$ARG" = "-h" -o "$ARG" == "--help" ]; then help; exit 0
|
|
elif [ "$ARG" = "-w" -o "$ARG" == "--wconf" ]; then writeconf; exit
|
|
else
|
|
if [ -z "$NAME" -a -n $ARG ]; then
|
|
NAME=$ARG
|
|
elif [ -z "$NOTEBOOK" -a -n $ARG ]; then
|
|
NOTEBOOK=$ARG
|
|
elif [ -z "$SECTION" -a -n $ARG ]; then
|
|
SECTION=$ARG
|
|
fi
|
|
fi
|
|
done
|
|
if [ -n "$NAME" -a -z "$NOTEBOOK" ]; then
|
|
NOTEBOOK="$NAME"
|
|
NAME=""
|
|
fi
|
|
fi
|
|
|
|
# Note: writeconf has highest priority, and it is the only function that can
|
|
# work without any parameters.
|
|
|
|
#==============================================================================
|
|
# End Section: Argument Parsing
|
|
#==============================================================================
|