Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,58 @@ help() {
echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
}

print_menu () {
folderPath=$1
versionSelected=$2
ogPath=$3
echo "Select an operation:"
echo "[1] Read a Version"
echo "[2] Rollback a Version"
echo "[3] Exit"

read -p "Enter your choice: " choice

if [ "$choice" == "1" ]; then
echo "You selected 'Read a Version'."
cat "${folderPath}/${versionSelected}"
print_menu folderPath versionSelected
elif [ "$choice" == "2" ]; then
echo "$ogPath"
cat "${folderPath}/${versionSelected}" > "$ogPath"
echo "Rollback was succesfull"
elif [ "$choice" == "3" ]; then
echo "Exiting"
exit 0
else
echo "Invalid choice. Please enter 1 or 2."
print_menu folderPath versionSelected ogPath
fi
}

roll-back () {
fileName="$1"
folderName="./${2}"
versionsPath="./versions/${fileName}_versions"
file_path="$folderName$fileName"

if [ -e "$file_path" ]; then
echo "File Found, Select an Operation:"
echo "Versions Available:"
ls "$versionsPath"
read -p "Enter complete name of the version: " versionSelected
if [ -e "$versionsPath/${versionSelected}" ]; then
echo "Version Found"
print_menu $versionsPath $versionSelected $file_path
else
echo "Version does not exist"
root_function
fi
else
echo "File does not exist"
fi
}


while getopts ":c:r:f:m:" opt; do
case $opt in
c)
Expand Down Expand Up @@ -312,6 +364,9 @@ case "$command" in
exit 1
fi
;;
"roll-back")
roll-back "$repo" "$file"
;;
"help")
help
;;
Expand Down