Made changes to create and delete functions reflecting recent design decisions

This commit is contained in:
Jon-William Lewis
2016-02-15 01:18:44 -06:00
parent faab86dff2
commit 037fd9c2fa
3 changed files with 27 additions and 31 deletions

View File

@@ -1,31 +1,35 @@
function create(){ function create(){
# Depends : p_header # Depends : p_header
# Requires: $NOTE, $NOTE_DIR, $NOTEBOOK, $SECTION, $NAME # Requires: $NOTE, $NOTE_DIR,
# Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt # Optional: $ENCRYPTION, $SESSION_ID, $TMP_DIR encrypt
# Given a valid setup, create writes the standard note header as specified # Given a valid setup, create writes the standard note header as specified
# by p_header, to $NOTE. # by p_header, to $NOTE.
# Refuse to overwrite a note # Refuse to overwrite a note
if [ -e "$NOTE" ]; then if [ -e "$NOTE_DIR/$NOTE" ]; then
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n" printf " $RED_COLOR!$RESET_COLOR %s\n\t%s\n"\
"Note already exists"\
"Hint: use -e to edit the note."
exit 200 exit 200
# If the notebook doesn't exist, create it.
elif [ ! -d "$NOTE_DIR" ]; then
mkdir -p "$NOTE_DIR"
fi fi
# If the note's notebook/section does not exist,
# create the appropriate folders.
mkdir -p "$NOTE_DIR"/$(dirname "$NOTE")
# Write the standard note header # Write the standard note header
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
TMP_NOTE="$TMP_DIR"/"$SESSION_ID" TMP_NOTE="$TMP_DIR"/"$SESSION_ID"
p_header > "$TMP_NOTE" p_header > "$TMP_NOTE"
encrypt encrypt
else else
p_header > "$NOTE" p_header > "$NOTE_DIR/$NOTE"
fi fi
# Make sure the note exists, and inform the user. # Make sure the note exists, and inform the user of the result.
if [ -e "$NOTE" ]; then if [ -e "$NOTE_DIR/$NOTE" ]; then
echo "Created note: $NOTEBOOK/$SECTION/$NAME." printf " - %s\n" "Created note: ${NOTE%.*}"
else else
printf "%s\n" "Something went wrong." printf " $RED_COLOR!$RESET_COLOR%s\n"\
"Something went wrong, and the note was not created."
fi fi
} }

View File

@@ -1,10 +1,11 @@
function delete(){ function delete(){
#Requires: $NOTE, $NOTEBOOK, $SECTION, $NAME # Requires: $NOTE, $NOTE_DIR
# Given a valid $NOTE, delete removes $NOTE from sns. # Given a valid $NOTE, delete removes $NOTE from sns.
if [ -e "$NOTE" ]; then
rm "$NOTE" if [ -e "$NOTE_DIR/$NOTE" ]; then
printf "\n%s\n" "Deleted note: $NOTEBOOK/$SECTION/$NAME." rm "$NOTE_DIR/$NOTE"
printf " - %s\n" "Deleted note: ${NOTE%.*}."
else else
printf "\n%s\n" "ERROR: Note $NOTEBOOK/$SECTION/$NAME does not exist." printf " $RED_COLOR!$RESET_COLOR %s\n" "Note ${NOTE%.*} does not exist."
fi fi
} }

View File

@@ -12,26 +12,17 @@ if [ -z "$NOTE" ]; then
printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified." printf " $RED_COLOR!$RESET_COLOR %s\n" "No note specified."
exit 30 exit 30
fi fi
# List is the only option requiring only a notebook.
# If list isn't the selected option and no note name was specified, throw code 30.
if [ "$LIST" == TRUE ]; then
list
exit 0
elif [ -z "$NAME" ]; then
printf "\n%s\n %s\n" "ERROR: Insufficient arguments:" "Notebook not specified"
exit 30
fi
NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION" NOTE_DIR="$NOTES_DIR"/"$NOTEBOOK"/"$SECTION"
if [ "$ENCRYPTION" == "TRUE" ]; then if [ "$ENCRYPTION" == "TRUE" ]; then
SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename SESSION_ID="$RANDOM" #SESSION_ID later becomes the temporary filename
readonly NOTE="$NOTE_DIR/$NAME.$EXT.gpg" readonly NOTE="$NOTE.$EXT.gpg"
else else
readonly NOTE="$NOTE_DIR/$NAME.$EXT" readonly NOTE="$NOTE.$EXT"
fi fi
if [ "$LIST" == "TRUE" ]; then list; exit 0; fi
if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
if [ "$CREATE" == "TRUE" ]; then create; fi if [ "$CREATE" == "TRUE" ]; then create; fi