sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

getopt-test.sh (1944B)


      1 #!/bin/bash
      2 
      3 # # usage
      4 #
      5 # declare "${_ble_getopt_locals[@]}"
      6 # ble/getopt.init "$0" "$@"
      7 #
      8 # while ble/getopt.next; do
      9 #   case $option in
     10 #   (-a|--hoge)
     11 #     echo hoge ;;
     12 #   esac
     13 # done
     14 #
     15 # if ! ble/getopt.finalize; then
     16 #   print-usage
     17 #   return 1
     18 # fi
     19 
     20 source getopt.sh
     21 
     22 function command1 {
     23   builtin eval -- "$_ble_getopt_prologue"
     24   ble/getopt.init "$0" "$@"
     25 
     26   while ble/getopt.next; do
     27     case $option in
     28     (-b|--bytes)  ble/util/print bytes  ;;
     29     (-s|--spaces) ble/util/print spaces ;;
     30     (-w|--width)
     31       if ! ble/getopt.get-optarg; then
     32         ble/getopt.print-argument-message "missing an option argument for $option"
     33         getopt_error=1
     34         continue
     35       fi
     36       ble/util/print "width=$optarg" ;;
     37     (--char-width|--tab-width|--indent-type)
     38       if ! ble/getopt.get-optarg; then
     39         ble/getopt.print-argument-message "missing an option argument for $option"
     40         getopt_error=1
     41         continue
     42       fi
     43       ble/util/print "${option#--} = $optarg" ;;
     44     (--continue)
     45       if ble/getopt.has-optarg; then
     46         ble/getopt.get-optarg
     47         ble/util/print "continue = $optarg"
     48       else
     49         ble/util/print "continue"
     50       fi ;;
     51     (-i|--indent)
     52       if ble/getopt.has-optarg; then
     53         ble/getopt.get-optarg
     54         ble/util/print "indent = $optarg"
     55       else
     56         ble/util/print "indent"
     57       fi ;;
     58     (--text-justify|--no-text-justify)
     59       ble/util/print "${option#--}" ;;
     60     (-[^-]*|--?*)
     61       ble/getopt.print-argument-message "unknown option."
     62       getopt_error=1 ;;
     63     (*)
     64       ble/getopt.print-argument-message "unknown argument."
     65       getopt_error=1 ;;
     66     esac
     67   done
     68 
     69   if ! ble/getopt.finalize; then
     70     ble/util/print "usage: getopt-test.sh [options]" >&2
     71     builtin exit 1
     72   fi
     73 }
     74 
     75 command1 -b --bytes -w 1 --width 10 --width=123 \
     76          --char-width --continue=10 --continue \
     77          -i --indent --indent= \
     78          --text-justify --unknown argument
     79