Skip to content

Commit

Permalink
Avoid pollution with global variables in info commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jansorg committed Oct 8, 2024
1 parent 1daa08b commit 2b52cad
Showing 1 changed file with 43 additions and 41 deletions.
84 changes: 43 additions & 41 deletions command/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,60 @@ typeset -A _Dbg_command_help_info
_Dbg_help_add info '' 1 _Dbg_complete_info

# Load in "info" subcommands
for _Dbg_file in "${_Dbg_libdir}/command/info_sub/"*.sh ; do
source "$_Dbg_file"
for _Dbg_file in "${_Dbg_libdir}/command/info_sub/"*.sh; do
source "$_Dbg_file"
done

# Command completion
_Dbg_complete_info() {
_Dbg_complete_subcmd info
_Dbg_complete_subcmd info
}

_Dbg_do_info() {
if (($# > 0)); then
typeset _Dbg_subcmd="$1"
shift

if (($# > 0)) ; then
typeset subcmd=$1
shift
if [[ -n ${_Dbg_debugger_info_commands["$_Dbg_subcmd"]} ]]; then
${_Dbg_debugger_info_commands["$_Dbg_subcmd"]} "$@"
return $?
else
# Look for a unique abbreviation
typeset -i _Dbg_found=0
typeset -i _Dbg_count=0
typeset _Dbg_list
_Dbg_list="${!_Dbg_debugger_info_commands[@]}"
for _Dbg_try in $_Dbg_list; do
if [[ $_Dbg_try =~ ^$_Dbg_subcmd ]]; then
_Dbg_subcmd="$_Dbg_try"
((_Dbg_count++))
fi
done
((_Dbg_found = (_Dbg_count == 1)))
fi
if ((_Dbg_found)); then
${_Dbg_debugger_info_commands["$_Dbg_subcmd"]} "$@"
return $?
fi

typeset -i found=0

if [[ -n ${_Dbg_debugger_info_commands[$subcmd]} ]] ; then
${_Dbg_debugger_info_commands[$subcmd]} "$@"
return $?
else
# Look for a unique abbreviation
typeset -i count=0
typeset list; list="${!_Dbg_debugger_info_commands[@]}"
for try in $list ; do
if [[ $try =~ ^$subcmd ]] ; then
subcmd=$try
((count++))
fi
done
((found=(count==1)))
fi
if ((found)); then
${_Dbg_debugger_info_commands[$subcmd]} "$@"
return $?
fi

_Dbg_errmsg "Unknown info subcommand: $subcmd"
msg=_Dbg_errmsg
_Dbg_errmsg "Unknown info subcommand: $_Dbg_subcmd"
_Dbg_msg=_Dbg_errmsg
else
msg=_Dbg_msg
_Dbg_msg=_Dbg_msg
fi
typeset -a list
list=(${!_Dbg_debugger_info_commands[@]})
sort_list 0 ${#list[@]}-1
typeset columnized=''
typeset -i width; ((width=_Dbg_set_linewidth-5))
typeset -a columnized; columnize $width
typeset -i i
$msg "Info subcommands are:"
for ((i=0; i<${#columnized[@]}; i++)) ; do
$msg " ${columnized[i]}"

typeset -a _Dbg_list
_Dbg_list=(${!_Dbg_debugger_info_commands[@]})
sort_list 0 ${#_Dbg_list[@]}-1
typeset _Dbg_columnized=''
typeset -i _Dbg_width
((_Dbg_width = _Dbg_set_linewidth - 5))
typeset -a _Dbg_columnized
columnize $_Dbg_width
typeset -i _Dbg_i
$_Dbg_msg "Info subcommands are:"
for ((_Dbg_i = 0; _Dbg_i < ${#_Dbg_columnized[@]}; _Dbg_i++)); do
$_Dbg_msg " ${_Dbg_columnized[_Dbg_i]}"
done
return 1
}
Expand Down

0 comments on commit 2b52cad

Please sign in to comment.