lib/update.args
changeset 575 b68b8615c512
child 578 a2d87cfd77e4
equal deleted inserted replaced
574:c486df8ea68a 575:b68b8615c512
       
     1 # vim: set ft=sh :
       
     2 #
       
     3 # Command-line option handling
       
     4 
       
     5 # use color output?
       
     6 IS_TTY=
       
     7 
       
     8 
       
     9 ## Options
       
    10 LOG_ERROR=y
       
    11 LOG_WARN=y
       
    12 LOG=y
       
    13 LOG_FORCE=y
       
    14 LOG_UPDATE=y
       
    15 LOG_NOOP=y
       
    16 LOG_SKIP=
       
    17 LOG_DEBUG=
       
    18 LOG_CMD=
       
    19 
       
    20 UPDATE_FORCE=
       
    21 UPDATE_NOOP=
       
    22 UPDATE_DIFF=
       
    23 
       
    24 SERIAL_NOOP=
       
    25 SERIAL_FORCE=
       
    26 
       
    27 COMMIT_SKIP=
       
    28 COMMIT_FORCE=
       
    29 COMMIT_MSG=' '
       
    30 
       
    31 DEPLOY_SKIP=
       
    32 
       
    33 ## Output command-line argument help.
       
    34 function help_args {
       
    35     local prog=$1
       
    36 
       
    37     cat <<END
       
    38 Usage: $prog [options]
       
    39 
       
    40 General:
       
    41     -h      display this help text
       
    42     -d DIR  datadir
       
    43 
       
    44 Logging:    
       
    45     -q      quiet
       
    46     -v      verbose
       
    47     -D      debug
       
    48     -V      debug commands
       
    49     
       
    50 Updates:
       
    51     -p      show changes
       
    52     -F      force-updates without checking src mtime
       
    53     -S      do not update serial
       
    54     -s      update serials
       
    55     -n      no-op/mock-update; don't actually change/deploy anything; implies -SpC
       
    56 
       
    57 Commit:
       
    58     -C      do not commit changes
       
    59     -c      commit changes
       
    60     -m MSG  commit message
       
    61 END
       
    62 }
       
    63 
       
    64 ## Parse any command-line arguments, setting the global options vars.
       
    65 function parse_args {
       
    66     OPTIND=1
       
    67 
       
    68     while getopts 'hd:qvDVpFSsnCcm:' opt "$@"; do
       
    69         case $opt in
       
    70             h)  
       
    71                 help_args $0
       
    72                 exit 0
       
    73             ;;
       
    74 
       
    75             d)  ROOT="$OPTARG" ;;
       
    76 
       
    77             q)  
       
    78                 LOG= 
       
    79                 LOG_WARN=
       
    80                 LOG_UPDATE=
       
    81                 LOG_FORCE=
       
    82                 LOG_NOOP=
       
    83                 ;;
       
    84 
       
    85             v)  LOG_SKIP=y ;;
       
    86             D)  
       
    87                 LOG_DEBUG=y
       
    88                 LOG_INFO=y
       
    89                 ;;
       
    90             V)  LOG_CMD=y ;;
       
    91 
       
    92             p)  UPDATE_DIFF=y   ;;
       
    93             F)  UPDATE_FORCE=y  ;;
       
    94             S)  SERIAL_NOOP=y   ;;
       
    95             s)  SERIAL_FORCE=y  ;;
       
    96  
       
    97             n)  
       
    98                 UPDATE_NOOP=y 
       
    99                 # implies -Sp
       
   100                 UPDATE_DIFF=y
       
   101                 SERIAL_NOUPDATE=y
       
   102                 COMMIT_SKIP=y
       
   103                 DEPLOY_SKIP=y
       
   104                 ;;
       
   105 
       
   106             C)  COMMIT_SKIP=y ;;
       
   107             c)  COMMIT_FORCE=y ;;
       
   108             m)  COMMIT_MSG="$OPTARG" ;;
       
   109            
       
   110             ?)  
       
   111                 die 
       
   112             ;;
       
   113         esac
       
   114 
       
   115     done
       
   116 }
       
   117 
       
   118