Commit 51305b79 authored by Emeric Verschuur's avatar Emeric Verschuur

Add mode non interactive as default mode option

parent f8698895
......@@ -145,14 +145,15 @@ bashopts_tool_name=$0
# STEP 1: setup
bashopts_setup() {
local arg arglist no_default_opts
if ! arglist=$(getopt -o "n:d:u:s:fp" -n "$0 " -- "$@"); then
local arg arglist no_default_opts non_interactive disable_interactive
if ! arglist=$(getopt -o "n:d:u:s:yxp" -n "$0 " -- "$@"); then
bashopts_error "Usage bashopts_setup:" \
" -n <val> Tool name" \
" -d <val> Tool description" \
" -u <val> Tool usage description" \
" -s <val> setting file path" \
" -f Force edition if ineractive options (default: only if not defined via the cmd line)"
" -y Set non interactive mode as the default mode" \
" -x Disable entirely interactive mode" \
" -p Force value storage even if the value is equal to the default one"
return 1
fi
......@@ -166,7 +167,8 @@ bashopts_setup() {
-d) bashopts_tool_description=$1; shift;;
-u) bashopts_tool_usage=$1; shift;;
-s) bashopts_tool_settings_path=$1; shift;;
-f) bashopts_tool_force_edit="true";;
-y) non_interactive="true";;
-x) disable_interactive="true";;
-p) bashopts_tool_settings_force_write="true";;
--) break;;
*) bashopts_error "Fatal error";;
......@@ -180,9 +182,15 @@ bashopts_setup() {
fi
bashopts_tool_usage=${bashopts_tool_usage:-"$bashopts_tool_name [options and commands] [-- [extra args]]"}
# add the default options
if [ "$no_default_opts" != "true" ]; then
bashopts_declare -n __bashopts_display_help__ -l help -o h -d "Display this help"
bashopts_declare -n bashopts_non_interactive -l non-interactive -o n -d "Non interactive mode"
bashopts_declare -n __bashopts_display_help__ -l help -o h -d "Display this help"
if [ "$disable_interactive" == "true" ]; then
bashopts_interactive="false"
else
if [ "$non_interactive" == "true" ]; then
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"
fi
fi
}
......@@ -521,7 +529,7 @@ bashopts_dump_array() {
bashopts_process_args() {
local dval ival
if [ "$__bashopts_display_help__" == "true" ]; then
bashopts_non_interactive="true"
bashopts_interactive="false"
fi
for op in "${bashopts_optlist[@]}"; do
unset dval
......@@ -533,7 +541,7 @@ bashopts_process_args() {
else
dval=${bashopts_optprop_default[$op]}
fi
if ! [[ -v $op ]] || [ "$bashopts_tool_force_edit" == "true" ]; then
if ! [[ -v $op ]]; then
unset tval
# read the value from file
if ! [[ -v $op ]] && [ "${bashopts_optprop_setting[$op]}" == "true" ] \
......@@ -545,7 +553,7 @@ bashopts_process_args() {
# set default value
eval "tval=$(bashopts_get_def dval)"
fi
if [ "${bashopts_optprop_interactive[$op]}" == "true" ] && [ "$bashopts_non_interactive" != "true" ]; then
if [ "${bashopts_optprop_interactive[$op]}" == "true" ] && [ "$bashopts_interactive" == "true" ]; then
# interactive edition
while true; do
echo "* ${bashopts_optprop_description[$op]}"
......@@ -617,6 +625,13 @@ bashopts_process_args() {
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"
else
bashopts_interactive="true"
fi
fi
done
if [ "$__bashopts_display_help__" == "true" ]; then
bashopts_diplay_help
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment