corriger simple_menu et actions_menu
This commit is contained in:
parent
04e25b5700
commit
69f3ab76b1
|
@ -6,7 +6,7 @@ function: local_args "Afficher des commandes pour rendre locales des variables u
|
|||
|
||||
Cela permet d'utiliser parse_args() à l'intérieur d'une fonction."
|
||||
function local_args() {
|
||||
echo "local args"
|
||||
echo "local -a args"
|
||||
echo "local NULIB_ARGS_ONERROR_RETURN=1"
|
||||
echo "local NULIB_VERBOSITY=\"\$NULIB_VERBOSITY\""
|
||||
echo "local NULIB_INTERACTION=\"\$NULIB_INTERACTION\""
|
||||
|
|
|
@ -234,10 +234,14 @@ function simple_menu() {
|
|||
# -m YOUR_CHOICE: spécifier le message d'invite pour la sélection de l'option
|
||||
# -d DEFAULT: spécifier l'option par défaut. Par défaut, prendre la valeur
|
||||
# actuelle de la variable $1(=option)
|
||||
eval "$(local_args)"
|
||||
local __sm_title= __sm_yourchoice= __sm_default=
|
||||
local -a __sm_args
|
||||
parse_opts -t: __sm_title= -m: __sm_yourchoice= -d: __sm_default= @ __sm_args -- "$@" &&
|
||||
set -- "${__sm_args[@]}" || ewarn "$__sm_args"
|
||||
args=(
|
||||
-t:,--title __sm_title=
|
||||
-m:,--prompt __sm_yourchoice=
|
||||
-d:,--default __sm_default=
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
local __sm_option_var="${1:-option}" __sm_options_var="${2:-options}"
|
||||
local __sm_option __sm_options
|
||||
|
@ -322,20 +326,21 @@ function actions_menu() {
|
|||
# choix. par défaut, c'est la dernière action.
|
||||
# -o DEFAULT_OPTION: choisir l'option par défaut. par défaut, prendre la valeur
|
||||
# actuelle de la variable $2(=option)
|
||||
eval "$(local_args)"
|
||||
local -a __am_action_descs __am_options __am_void_actions
|
||||
local __am_tmp __am_select_action __am_select_option __am_title __am_optyc __am_actyc
|
||||
local __am_default_action=auto __am_quit_action=auto
|
||||
local __am_default_option=
|
||||
local -a __am_args
|
||||
parse_opts \
|
||||
-t: __am_title= \
|
||||
-m: __am_optyc= \
|
||||
-M: __am_actyc= \
|
||||
-e: __am_void_actions \
|
||||
-d: __am_default_action= \
|
||||
-q: __am_quit_action= \
|
||||
-o: __am_default_option= \
|
||||
@ __am_args -- "$@" && set -- "${__am_args[@]}" || { eerror "$__am_args"; return 1; }
|
||||
args=(
|
||||
-t:,--title __am_title=
|
||||
-m:,--prompt __am_optyc=
|
||||
-M:,--no-prompt __am_actyc=
|
||||
-e: __am_void_actions
|
||||
-d: __am_default_action=
|
||||
-q: __am_quit_action=
|
||||
-o: __am_default_option=
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
__am_tmp="${1:-action}"; __am_select_action="${!__am_tmp}"
|
||||
__am_tmp="${2:-option}"; __am_select_option="${!__am_tmp}"
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname -- "$0")/../src/nulib.sh" || exit 1
|
||||
#NULIB_NO_DISABLE_SET_X=1
|
||||
|
||||
args=(
|
||||
"tester diverses fonctions de saisie"
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
choices=(first second third)
|
||||
choice=
|
||||
simple_menu -t "choix sans valeur par défaut" -m "le prompt" choice choices
|
||||
enote "vous avez choisi choice=$choice"
|
||||
|
||||
choice=second
|
||||
simple_menu -t "choix avec valeur par défaut" -m "le prompt" choice choices
|
||||
enote "vous avez choisi choice=$choice"
|
Loading…
Reference in New Issue