diff options
author | Andrew Robbins <contact@andrewrobbins.info> | 2017-07-09 03:22:45 -0400 |
---|---|---|
committer | Andrew Robbins <contact@andrewrobbins.info> | 2017-07-09 03:22:45 -0400 |
commit | 9b5d012ec4c2cfa32f05e3a668bcd2b2d17507ac (patch) | |
tree | db0ed50fcee5ef2b6673b3e8416e35a59505d36d | |
parent | 74a0a67599f043dd43c9ea3cc3766fcf078c1ad7 (diff) | |
download | librebootfr-9b5d012ec4c2cfa32f05e3a668bcd2b2d17507ac.tar.gz librebootfr-9b5d012ec4c2cfa32f05e3a668bcd2b2d17507ac.zip |
Fix action text in './libreboot usage <project>'
Apparently the name used in a 'for /name/ ...' loop rebinds any local
variables (with the same name) with whatever /name/ is bound
to in a way that persists even after the loop returns. The crux of
the issue here is that a function's children can rebind the parent(s)'
local variables just by using the same name as the variable in a for
loop, which is surprising--and apparently undocumented--behavior.
Use of a subshell group for encapsulating the for loops (See:
project_usage_actions) mitigates the aforementioned issue.
Closes issue: #244
-rwxr-xr-x | libs/project | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/libs/project b/libs/project index 43c6a82c..2728d4fa 100755 --- a/libs/project +++ b/libs/project @@ -556,56 +556,54 @@ project_arguments_targets() { } project_usage_actions() { - local project=$1 + local project="$1" shift printf '\n%s\n' 'Generic actions:' - for action in $PROJECT_ACTIONS_GENERIC - do - if function_check "$action" - then - printf '%s\n' " $action" - fi - done + ( + for action in ${PROJECT_ACTIONS_GENERIC}; do + if function_check "${action}"; then + printf '%s\n' " ${action}" + fi + done + ) - if [ $# -gt 0 ] - then + if [[ "$#" -gt 0 ]]; then printf '\n%s\n' 'Specific actions:' - for action in "$@" - do - printf '%s\n' " $action" - done + ( + for action in "$@"; do + printf '%s\n' " ${action}" + done + ) fi } project_usage_arguments() { - local project=$1 + local project="$1" shift printf '\n%s\n' 'Arguments:' - project_usage_arguments_recursive "$project" " " "$@" + project_usage_arguments_recursive "${project}" ' ' "$@" } project_usage_arguments_recursive() { - local project=$1 + local project="$1" shift - local spacing=$1 + local spacing="$1" shift local action_helper_arguments local argument - action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" ) + action_helper_arguments="$(project_action_helper 'arguments' "${project}" "$@")" - if ! [ -z "$action_helper_arguments" ] - then - printf '%s\n' "$action_helper_arguments" | while read argument - do - printf '%s\n' "$spacing$argument" - project_usage_arguments_recursive "$project" " $spacing" "$@" "$argument" + if [[ -n "${action_helper_arguments}" ]]; then + for argument in ${action_helper_arguments}; do + printf '%s\n' "${spacing}${argument}" + project_usage_arguments_recursive "${project}" " ${spacing}" "$@" "${argument}" done fi } |