Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .agents/scripts/wp-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@
local site_type
site_type=$(echo "$site_config" | jq -r '.type')

print_info "Running on $site_name ($site_type): wp ${wp_args[*]}" >&2
local args_str
args_str=$(printf '%q ' "${wp_args[@]}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using command substitution $(...) creates a subshell. To make this more efficient and align with the goal of avoiding subshells, you can use printf -v. This bash feature assigns the output directly to the variable without creating a new process.

Suggested change
args_str=$(printf '%q ' "${wp_args[@]}")
printf -v args_str '%q ' "${wp_args[@]}"
References
  1. In shell scripts, avoid spawning subshells for string manipulations to improve performance. Using printf -v aligns with this principle by assigning output directly to a variable without creating a new process, similar to using pure Bash parameter expansion.

print_info "Running on $site_name ($site_type): wp ${args_str% }" >&2

# Execute directly without eval
execute_wp_via_ssh "$site_config" "${wp_args[@]}"
Expand All @@ -401,7 +403,9 @@
load_config

print_info "Running on all sites in category: $category"
print_info "Command: wp ${wp_args[*]}"
local args_str
args_str=$(printf '%q ' "${wp_args[@]}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using command substitution $(...) creates a subshell. To make this more efficient and align with the goal of avoiding subshells, you can use printf -v. This bash feature assigns the output directly to the variable without creating a new process.

Suggested change
args_str=$(printf '%q ' "${wp_args[@]}")
printf -v args_str '%q ' "${wp_args[@]}"
References
  1. In shell scripts, avoid spawning subshells for string manipulations to improve performance. Using printf -v aligns with this principle by assigning output directly to a variable without creating a new process, similar to using pure Bash parameter expansion.

print_info "Command: wp ${args_str% }"
echo ""

local site_keys
Expand Down Expand Up @@ -444,7 +448,9 @@
load_config

print_info "Running on ALL sites"
print_info "Command: wp ${wp_args[*]}"
local args_str
args_str=$(printf '%q ' "${wp_args[@]}")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using command substitution $(...) creates a subshell. To make this more efficient and align with the goal of avoiding subshells, you can use printf -v. This bash feature assigns the output directly to the variable without creating a new process.

Suggested change
args_str=$(printf '%q ' "${wp_args[@]}")
printf -v args_str '%q ' "${wp_args[@]}"
References
  1. In shell scripts, avoid spawning subshells for string manipulations to improve performance. Using printf -v aligns with this principle by assigning output directly to a variable without creating a new process, similar to using pure Bash parameter expansion.

print_info "Command: wp ${args_str% }"
echo ""

local site_keys
Expand Down Expand Up @@ -537,7 +543,7 @@
echo " [skip] .aidevops-tenant (not found)"
fi
if [[ -f "$WP_ACTIVE_TENANT_FILE" ]]; then
echo " [found] active-tenant = $(tr -d '[:space:]' <"$WP_ACTIVE_TENANT_FILE")"

Check warning on line 546 in .agents/scripts/wp-helper.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of using the literal '[:space:]' 4 times.

See more on https://sonarcloud.io/project/issues?id=marcusquinn_aidevops&issues=AZzy2P0Fa2oXHuy7vb05&open=AZzy2P0Fa2oXHuy7vb05&pullRequest=4953
else
echo " [skip] active-tenant (not set)"
fi
Expand Down
Loading