reimplemented title dialog when adding note if nothing is passed on the command line.
[bash-notes.git] / SOURCE / main.sh
index da3130a..c2822d9 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,showconf,sync,restore:,backup:,add::,edit:,delete:,show: -n 'bash-notes' -- "$@")
 
 # shellcheck disable=SC2181
 if [ $? != 0 ] ; then helptext >&2 ; exit 1 ; fi
@@ -27,52 +27,40 @@ while true; do
                        exit
                ;;
            -a | --add )
-                       case "$2" in
-                               '' )
-                                       read -r -p "Title: " TITLE
-                                       ;;
-                               * )
-                                       TITLE=$2
-                                       ;;
-                       esac
+                       TITLE=$2
                        shift 2
                        addnote "$TITLE"
+                       exit
                ;;
                -e | --edit )
-                       case "$2" in
-                               '' )
-                                       read -r -p "Note ID: " NOTE
-                                       ;;
-                               * )
-                                       NOTE=$2
-                                       ;;
-                       esac
+                       NOTE=$2
                        shift 2
                        editnote "$NOTE"
+                       exit
                        ;;
                -d | --delete )
-                       case "$2" in
-                               '' )
-                                       read -r -p "Note ID: " NOTE
-                                       ;;
-                               * )
-                                       NOTE=$2
-                                       ;;
-                       esac
+                       NOTE=$2
                        shift 2
                        rmnote "$NOTE"
+                       exit
                        ;;
                -s | --show )
-                       case "$2" in
-                               '' )
-                                       read -r -p "Note ID: " NOTE
-                                       ;;
-                               * )
-                                       NOTE=$2
-                                       ;;
-                       esac
+                       NOTE=$2
                        shift 2
                        shownote "$NOTE"
+                       exit
+                       ;;
+               -r | --restore )
+                       RDIR=$2
+                       shift 2
+                       backup_restore $RDIR
+                       exit
+                       ;;
+               --sync )
+                       # I'm forcing it because if you run it manually, chances are that you need to.
+                       gitsync -f
+                       shift
+                       exit
                        ;;
                --userconf )
                        export_config
@@ -81,6 +69,16 @@ while true; do
                        # shellcheck disable=SC2317
                        exit
                        ;;
+               --showconf )
+                       configtext
+                       exit
+                       ;;
+               --backup )
+                       BDIR=$2
+                       shift 2
+                       backup_data $BDIR
+                       exit
+                       ;;
                -- )
                        shift
                        break
@@ -91,6 +89,11 @@ while true; do
        esac
 done
 
-if [ -z $1 ]; then
-       helptext
-fi
+for arg; do
+       if [ $(check_noteID $arg) ]; then
+               shownote $arg
+       else
+               helptext
+               exit
+       fi
+done