Skip to content

Commit

Permalink
bash: use compgen to get function lists
Browse files Browse the repository at this point in the history
Simpler than use custom declare() methods.
  • Loading branch information
radhermit committed Nov 21, 2015
1 parent d2517ae commit 2e31a68
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
14 changes: 1 addition & 13 deletions bash/ebuild-env-utils.lib
Expand Up @@ -45,18 +45,6 @@ __escape_regex_array() {
eval $1='( "${__tmp_array[@]}" )'
} &> /dev/null

__environ_list_funcs() {
# Grab the vars /before/ adding our custom declare function, else it'll
# show up in the list of functions.
local __content=$(builtin declare -F)
declare() {
echo "$2"
}
eval "${__content}" || die "${FUNCNAME}: eval failed" >&2
unset -f declare
:
}

__environ_list_vars() {
declare() {
local __ret=${2%%=*}
Expand Down Expand Up @@ -84,7 +72,7 @@ __environ_dump() {

# Punt any regex chars...
__escape_regex_array __func_filters
__PKGCORE_TARGETS=( $(__environ_list_funcs | __regex_filter_input "${__func_filters[@]}" ) )
__PKGCORE_TARGETS=( $(compgen -A function | __regex_filter_input "${__func_filters[@]}" ) )
unset __func_filters
if [[ ${#__PKGCORE_TARGETS[@]} -ne 0 ]]; then
declare -f "${__PKGCORE_TARGETS[@]}" || die "failed outputting funcs ${__PKGCORE_TARGETS[@]}" >&2
Expand Down
7 changes: 1 addition & 6 deletions bash/generate_eapi_func_list.bash
Expand Up @@ -18,13 +18,8 @@ export PKGCORE_PYTHON_BINARY=/bin/true
source "${PKGCORE_BIN_PATH}/eapi/${EAPI}.lib" \
|| { echo "failed loading eapi/${EAPI}.lib" >&2; exit 1; }

# grab function list *before* adding our custom declare function, otherwise
# it'll show up in the list of functions
__content=$(builtin declare -F)
declare() { echo "$2"; }
result=$(eval "${__content}") || { echo "generate EAPI func list eval failed" >&2; exit 1; }
result=$(compgen -A function)
# Sorting order; put PMS functionality first, then our internals.
result=$(echo "${result}" | grep -v "^__"; echo "${result}" | grep "^__")
unset -f declare

echo "${result}"
2 changes: 1 addition & 1 deletion bash/generate_global_func_list.bash
Expand Up @@ -64,7 +64,7 @@ unset -f __source_was_seen
unset -f source

# Sorting order; put PMS functionality first, then our internals.
result=$(__environ_list_funcs | sort)
result=$(compgen -A function | sort)
result=$(echo "${result}" | grep -v "^__"; echo "${result}" | grep "^__")
${DEBUG} && echo >&2
Expand Down

0 comments on commit 2e31a68

Please sign in to comment.