lib/update.args
changeset 575 b68b8615c512
child 578 a2d87cfd77e4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/update.args	Tue Mar 20 14:12:11 2012 +0200
@@ -0,0 +1,118 @@
+# vim: set ft=sh :
+#
+# Command-line option handling
+
+# use color output?
+IS_TTY=
+
+
+## Options
+LOG_ERROR=y
+LOG_WARN=y
+LOG=y
+LOG_FORCE=y
+LOG_UPDATE=y
+LOG_NOOP=y
+LOG_SKIP=
+LOG_DEBUG=
+LOG_CMD=
+
+UPDATE_FORCE=
+UPDATE_NOOP=
+UPDATE_DIFF=
+
+SERIAL_NOOP=
+SERIAL_FORCE=
+
+COMMIT_SKIP=
+COMMIT_FORCE=
+COMMIT_MSG=' '
+
+DEPLOY_SKIP=
+
+## Output command-line argument help.
+function help_args {
+    local prog=$1
+
+    cat <<END
+Usage: $prog [options]
+
+General:
+    -h      display this help text
+    -d DIR  datadir
+
+Logging:    
+    -q      quiet
+    -v      verbose
+    -D      debug
+    -V      debug commands
+    
+Updates:
+    -p      show changes
+    -F      force-updates without checking src mtime
+    -S      do not update serial
+    -s      update serials
+    -n      no-op/mock-update; don't actually change/deploy anything; implies -SpC
+
+Commit:
+    -C      do not commit changes
+    -c      commit changes
+    -m MSG  commit message
+END
+}
+
+## Parse any command-line arguments, setting the global options vars.
+function parse_args {
+    OPTIND=1
+
+    while getopts 'hd:qvDVpFSsnCcm:' opt "$@"; do
+        case $opt in
+            h)  
+                help_args $0
+                exit 0
+            ;;
+
+            d)  ROOT="$OPTARG" ;;
+
+            q)  
+                LOG= 
+                LOG_WARN=
+                LOG_UPDATE=
+                LOG_FORCE=
+                LOG_NOOP=
+                ;;
+
+            v)  LOG_SKIP=y ;;
+            D)  
+                LOG_DEBUG=y
+                LOG_INFO=y
+                ;;
+            V)  LOG_CMD=y ;;
+
+            p)  UPDATE_DIFF=y   ;;
+            F)  UPDATE_FORCE=y  ;;
+            S)  SERIAL_NOOP=y   ;;
+            s)  SERIAL_FORCE=y  ;;
+ 
+            n)  
+                UPDATE_NOOP=y 
+                # implies -Sp
+                UPDATE_DIFF=y
+                SERIAL_NOUPDATE=y
+                COMMIT_SKIP=y
+                DEPLOY_SKIP=y
+                ;;
+
+            C)  COMMIT_SKIP=y ;;
+            c)  COMMIT_FORCE=y ;;
+            m)  COMMIT_MSG="$OPTARG" ;;
+           
+            ?)  
+                die 
+            ;;
+        esac
+
+    done
+}
+
+