Skip to content

fix(wp-helper): use shell parameter expansion to trim trailing space in wp_args log#4953

Merged
marcusquinn merged 2 commits intomainfrom
fix/t4944-review-suggestions
Mar 15, 2026
Merged

fix(wp-helper): use shell parameter expansion to trim trailing space in wp_args log#4953
marcusquinn merged 2 commits intomainfrom
fix/t4944-review-suggestions

Conversation

@marcusquinn
Copy link
Owner

Summary

Addresses Gemini Code Assist review suggestion on PR #4950.

  • Replaces the subshell-in-string pattern $(printf '%q ' "${wp_args[@]}") with a two-step approach using shell parameter expansion ${args_str% } to trim the trailing space left by printf '%q '
  • Applied consistently to all three logging sites in wp-helper.sh: run_wp_command (line 383), run_on_category (line 404), and run_on_all (line 447)
  • Also fixes the remaining two sites that still used the ambiguous ${wp_args[*]} expansion (lines 404 and 447), which were flagged by CodeRabbit on PR t4944: Use printf %q for wp_args logging to handle spaces #4950

Why

Using ${args_str% } instead of a subshell inside a double-quoted string:

  1. Avoids spawning an extra subshell for a trivial string trim operation
  2. Is idiomatic pure-shell parameter expansion
  3. Keeps the local declaration and assignment on separate lines (ShellCheck-clean)

Related

alex-solovyev and others added 2 commits March 15, 2026 19:42
Replace subshell-in-string $(printf '%q ' ...) with a two-step pattern:
  local args_str; args_str=$(printf '%q ' "${wp_args[@]}")
  ... ${args_str% }

This avoids spawning an extra subshell inside the double-quoted string and
uses pure shell parameter expansion (${args_str% }) to strip the trailing
space left by printf '%q '. Applied to all three logging sites:
run_wp_command (line 383), run_on_category (line 404), run_on_all (line 447).

Addresses Gemini Code Assist suggestion on PR #4950.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Review skipped — only excluded labels are configured. (1)
  • no-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6bce5cc8-d65e-4767-845c-30ac03e35ff2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/t4944-review-suggestions
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the bug Auto-created from TODO.md tag label Mar 15, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the logging of wp command arguments within the wp-helper.sh script. It introduces a more efficient and robust method for trimming trailing spaces from argument strings, addressing previous review feedback. By leveraging pure-shell parameter expansion, the change enhances script performance and maintainability, ensuring consistent and accurate command logging across various execution contexts.

Highlights

  • Improved Argument Logging: Replaced the subshell-in-string pattern $(printf '%q ' "${wp_args[@]}") with a two-step approach using shell parameter expansion ${args_str% } to accurately trim trailing spaces from logged wp command arguments.
  • Consistent Application: Applied the new logging mechanism consistently across all three wp-helper.sh functions: run_wp_command, run_on_category, and run_on_all.
  • Ambiguous Expansion Fix: Fixed remaining instances where the ambiguous ${wp_args[*]} expansion was used, ensuring correct argument handling.
  • Performance and Readability: The new approach avoids spawning an extra subshell for string trimming, uses idiomatic pure-shell parameter expansion, and maintains ShellCheck-clean code by separating local declaration and assignment.
Changelog
  • .agents/scripts/wp-helper.sh
    • Modified run_wp_command to use shell parameter expansion for trimming trailing spaces in wp_args logging.
    • Modified run_on_category to use shell parameter expansion for trimming trailing spaces in wp_args logging, replacing ambiguous array expansion.
    • Modified run_on_all to use shell parameter expansion for trimming trailing spaces in wp_args logging, replacing ambiguous array expansion.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 362 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 15 18:52:55 UTC 2026: Code review monitoring started
Sun Mar 15 18:52:55 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 362

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 362
  • VULNERABILITIES: 0

Generated on: Sun Mar 15 18:52:58 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses an issue with logging shell arguments by replacing the unsafe ${wp_args[*]} with a more robust method using printf '%q '. This improves correctness and readability, and the changes are applied consistently. I have a few suggestions to further improve the implementation by using printf -v to avoid creating subshells, which aligns with the performance goals stated in the pull request description and with established repository rules regarding subshell avoidance for performance.


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

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 all sites in category: $category"
print_info "Command: wp ${wp_args[*]}"
local args_str
args_str=$(printf '%q ' "${wp_args[@]}")

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 ALL sites"
print_info "Command: wp ${wp_args[*]}"
local args_str
args_str=$(printf '%q ' "${wp_args[@]}")

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.

@marcusquinn marcusquinn merged commit ede0d00 into main Mar 15, 2026
24 checks passed
@marcusquinn marcusquinn deleted the fix/t4944-review-suggestions branch March 15, 2026 18:59
marcusquinn added a commit that referenced this pull request Mar 15, 2026
…ment

Replace $(printf '%q ' ...) with printf -v args_str '%q ' ... at lines 384,
407, and 452 to eliminate unnecessary subshell creation when building the
args_str display string. Addresses gemini review feedback from PR #4953.

Closes #4961
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants