Loading bashopts.sh +25 −14 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ bashopts_critical() { exit 1 } if [ ! "${BASH_VERSINFO[0]}" -ge 4 ]; then bashopts_critical "bashopts require BASH version 4 or greater" fi # display a error (non fatal) bashopts_error() { >&2 printf "[ERROR] %s\n" "$@" Loading Loading @@ -185,14 +189,14 @@ bashopts_setup() { fi bashopts_tool_usage=${bashopts_tool_usage:-"$bashopts_tool_name [options and commands] [-- [extra args]]"} # add the default options bashopts_declare -n __bashopts_display_help__ -l help -o h -d "Display this help" bashopts_declare -n __BASHOPTS_DISPLAY_HELP__ -l help -o h -d "Display this help" if [ "$disable_interactive" == "true" ]; then bashopts_interactive="false" BASHOPTS_INTERACTIVE="false" else if [ "$non_interactive" == "true" ]; then bashopts_declare -n bashopts_interactive -l interactive -o i -d "Interactive mode" bashopts_declare -n BASHOPTS_INTERACTIVE -l interactive -o i -d "Interactive mode" else bashopts_declare -n bashopts_non_interactive -l non-interactive -o n -d "Non interactive mode" bashopts_declare -n BASHOPTS_NON_INTERACTIVE -l non-interactive -o n -d "Non interactive mode" fi fi } Loading Loading @@ -412,6 +416,11 @@ bashopts_diplay_help() { test "$1" != "-e" || exit $2 } # Enable help display on option process bashopts_diplay_help_delayed() { __BASHOPTS_DISPLAY_HELP__="true" } # display all otions values and properties bashopts_diplay_summary() { local elts desc_max_len=0 val dval Loading Loading @@ -529,6 +538,7 @@ bashopts_dump_array() { echo -n "]" } # Process a specified option bashopts_process_option() { local dval tval ival op arg arglist check val_req edit_req if ! arglist=$(getopt -o "n:k:r" -n "bashopts_process_option " -- "$@"); then Loading Loading @@ -583,7 +593,7 @@ bashopts_process_option() { # Check current value(s) for (( i=0; i<${#tval[@]}; i++)); do if ! $check "${tval[$i]}" > /dev/null; then if [ "$bashopts_interactive" != "true" ]; then if [ "$BASHOPTS_INTERACTIVE" != "true" ]; then bashopts_critical "Non interactive mode: Exit due to one or more error" fi # (re)enable edition Loading @@ -593,7 +603,7 @@ bashopts_process_option() { done elif [ "$val_req" == "true" ]; then bashopts_error "At least one value required" if [ "$bashopts_interactive" != "true" ]; then if [ "$BASHOPTS_INTERACTIVE" != "true" ]; then bashopts_critical "Non interactive mode: Exit due to one or more error" fi # (re)enable edition Loading @@ -605,7 +615,7 @@ bashopts_process_option() { eval "tval=$(bashopts_get_def dval)" fi if [ "$edit_req" == "true" ]; then if [ "$bashopts_interactive" == "true" ]; then if [ "$BASHOPTS_INTERACTIVE" == "true" ]; then # interactive edition while true; do echo "* ${bashopts_optprop_description[$op]}" Loading Loading @@ -677,11 +687,11 @@ bashopts_process_option() { bashopts_warning "No settings file specified" fi fi if [ "$op" == "bashopts_non_interactive" ] && ! [[ -v bashopts_interactive ]]; then if [ "$bashopts_non_interactive" == "true" ]; then bashopts_interactive="false" if [ "$op" == "BASHOPTS_NON_INTERACTIVE" ] && ! [[ -v BASHOPTS_INTERACTIVE ]]; then if [ "$BASHOPTS_NON_INTERACTIVE" == "true" ]; then BASHOPTS_INTERACTIVE="false" else bashopts_interactive="true" BASHOPTS_INTERACTIVE="true" fi fi } Loading @@ -689,18 +699,19 @@ bashopts_process_option() { # STEP 4: process arg bashopts_process_opts() { local op if [ "$__bashopts_display_help__" == "true" ]; then bashopts_interactive="false" if [ "$__BASHOPTS_DISPLAY_HELP__" == "true" ]; then BASHOPTS_INTERACTIVE="false" fi for op in "${bashopts_optlist[@]}"; do bashopts_process_option -n $op done if [ "$__bashopts_display_help__" == "true" ]; then if [ "$__BASHOPTS_DISPLAY_HELP__" == "true" ]; then bashopts_diplay_help exit 0 fi } # Export all option variables bashopts_export_opts() { for op in "${bashopts_optlist[@]}"; do if [[ -v $op ]]; then Loading Loading
bashopts.sh +25 −14 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ bashopts_critical() { exit 1 } if [ ! "${BASH_VERSINFO[0]}" -ge 4 ]; then bashopts_critical "bashopts require BASH version 4 or greater" fi # display a error (non fatal) bashopts_error() { >&2 printf "[ERROR] %s\n" "$@" Loading Loading @@ -185,14 +189,14 @@ bashopts_setup() { fi bashopts_tool_usage=${bashopts_tool_usage:-"$bashopts_tool_name [options and commands] [-- [extra args]]"} # add the default options bashopts_declare -n __bashopts_display_help__ -l help -o h -d "Display this help" bashopts_declare -n __BASHOPTS_DISPLAY_HELP__ -l help -o h -d "Display this help" if [ "$disable_interactive" == "true" ]; then bashopts_interactive="false" BASHOPTS_INTERACTIVE="false" else if [ "$non_interactive" == "true" ]; then bashopts_declare -n bashopts_interactive -l interactive -o i -d "Interactive mode" bashopts_declare -n BASHOPTS_INTERACTIVE -l interactive -o i -d "Interactive mode" else bashopts_declare -n bashopts_non_interactive -l non-interactive -o n -d "Non interactive mode" bashopts_declare -n BASHOPTS_NON_INTERACTIVE -l non-interactive -o n -d "Non interactive mode" fi fi } Loading Loading @@ -412,6 +416,11 @@ bashopts_diplay_help() { test "$1" != "-e" || exit $2 } # Enable help display on option process bashopts_diplay_help_delayed() { __BASHOPTS_DISPLAY_HELP__="true" } # display all otions values and properties bashopts_diplay_summary() { local elts desc_max_len=0 val dval Loading Loading @@ -529,6 +538,7 @@ bashopts_dump_array() { echo -n "]" } # Process a specified option bashopts_process_option() { local dval tval ival op arg arglist check val_req edit_req if ! arglist=$(getopt -o "n:k:r" -n "bashopts_process_option " -- "$@"); then Loading Loading @@ -583,7 +593,7 @@ bashopts_process_option() { # Check current value(s) for (( i=0; i<${#tval[@]}; i++)); do if ! $check "${tval[$i]}" > /dev/null; then if [ "$bashopts_interactive" != "true" ]; then if [ "$BASHOPTS_INTERACTIVE" != "true" ]; then bashopts_critical "Non interactive mode: Exit due to one or more error" fi # (re)enable edition Loading @@ -593,7 +603,7 @@ bashopts_process_option() { done elif [ "$val_req" == "true" ]; then bashopts_error "At least one value required" if [ "$bashopts_interactive" != "true" ]; then if [ "$BASHOPTS_INTERACTIVE" != "true" ]; then bashopts_critical "Non interactive mode: Exit due to one or more error" fi # (re)enable edition Loading @@ -605,7 +615,7 @@ bashopts_process_option() { eval "tval=$(bashopts_get_def dval)" fi if [ "$edit_req" == "true" ]; then if [ "$bashopts_interactive" == "true" ]; then if [ "$BASHOPTS_INTERACTIVE" == "true" ]; then # interactive edition while true; do echo "* ${bashopts_optprop_description[$op]}" Loading Loading @@ -677,11 +687,11 @@ bashopts_process_option() { bashopts_warning "No settings file specified" fi fi if [ "$op" == "bashopts_non_interactive" ] && ! [[ -v bashopts_interactive ]]; then if [ "$bashopts_non_interactive" == "true" ]; then bashopts_interactive="false" if [ "$op" == "BASHOPTS_NON_INTERACTIVE" ] && ! [[ -v BASHOPTS_INTERACTIVE ]]; then if [ "$BASHOPTS_NON_INTERACTIVE" == "true" ]; then BASHOPTS_INTERACTIVE="false" else bashopts_interactive="true" BASHOPTS_INTERACTIVE="true" fi fi } Loading @@ -689,18 +699,19 @@ bashopts_process_option() { # STEP 4: process arg bashopts_process_opts() { local op if [ "$__bashopts_display_help__" == "true" ]; then bashopts_interactive="false" if [ "$__BASHOPTS_DISPLAY_HELP__" == "true" ]; then BASHOPTS_INTERACTIVE="false" fi for op in "${bashopts_optlist[@]}"; do bashopts_process_option -n $op done if [ "$__bashopts_display_help__" == "true" ]; then if [ "$__BASHOPTS_DISPLAY_HELP__" == "true" ]; then bashopts_diplay_help exit 0 fi } # Export all option variables bashopts_export_opts() { for op in "${bashopts_optlist[@]}"; do if [[ -v $op ]]; then Loading