implemented backup and restore routines
[bash-notes.git] / SOURCE / main.sh
index da3130a..476243b 100644 (file)
@@ -1,5 +1,5 @@
 # shellcheck disable=SC2006
-GOPT=$(getopt -o hvpla::e::d::s:: --long help,version,list,plain,userconf,backup::,add::,edit::,delete::,show:: -n 'bash-notes' -- "$@")
+GOPT=$(getopt -o hvplr::a::e::d::s:: --long help,version,list,plain,userconf,restore::,backup::,add::,edit::,delete::,show:: -n 'bash-notes' -- "$@")
 
 # shellcheck disable=SC2181
 if [ $? != 0 ] ; then helptext >&2 ; exit 1 ; fi
@@ -37,6 +37,7 @@ while true; do
                        esac
                        shift 2
                        addnote "$TITLE"
+                       exit
                ;;
                -e | --edit )
                        case "$2" in
@@ -49,6 +50,7 @@ while true; do
                        esac
                        shift 2
                        editnote "$NOTE"
+                       exit
                        ;;
                -d | --delete )
                        case "$2" in
@@ -61,6 +63,7 @@ while true; do
                        esac
                        shift 2
                        rmnote "$NOTE"
+                       exit
                        ;;
                -s | --show )
                        case "$2" in
@@ -73,6 +76,20 @@ while true; do
                        esac
                        shift 2
                        shownote "$NOTE"
+                       exit
+                       ;;
+               -r | --restore )
+                       case "$2" in
+                               '' )
+                                       read -r -p "Backup Dir: " RDIR
+                                       ;;
+                               * )
+                                       RDIR=$2
+                                       ;;
+                       esac
+                       shift 2
+                       backup_restore $RDIR
+                       exit
                        ;;
                --userconf )
                        export_config
@@ -81,6 +98,19 @@ while true; do
                        # shellcheck disable=SC2317
                        exit
                        ;;
+               --backup )
+                       case "$2" in
+                               '' )
+                                       read -r -p "Backup Dir: " BDIR
+                                       ;;
+                               * )
+                                       BDIR=$2
+                                       ;;
+                       esac
+                       shift 2
+                       backup_data $BDIR
+                       exit
+                       ;;
                -- )
                        shift
                        break
@@ -90,7 +120,3 @@ while true; do
                        ;;
        esac
 done
-
-if [ -z $1 ]; then
-       helptext
-fi