Add environment variable configuration support to wp-cli.yml#6169
Merged
swissspidy merged 18 commits intomainfrom Mar 13, 2026
Merged
Add environment variable configuration support to wp-cli.yml#6169swissspidy merged 18 commits intomainfrom
swissspidy merged 18 commits intomainfrom
Conversation
- Add 'env' configuration key to config-spec.php - Create get_env_or_config() helper function in utils.php - Update get_cache_dir() to use config fallback - Update cache expiry/max_size to use config fallback - Update packages_dir to use config fallback - Add Behat tests for env variable configuration - Environment variables still take precedence over config Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Add env example to wp-cli.example.yml - Update JSON schema to include env property - Document that env values are fallbacks when env vars not set Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Add null check for runner->config in get_env_or_config() - Update schema description to clarify values are converted to strings - Allow both string and numeric types in schema (YAML parses numbers) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add ability to set environment variables in wp-cli.yml
Add environment variable configuration support to wp-cli.yml
Dec 14, 2025
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
swissspidy
reviewed
Dec 14, 2025
swissspidy
reviewed
Dec 14, 2025
swissspidy
reviewed
Dec 14, 2025
swissspidy
reviewed
Dec 14, 2025
- Add scenario testing WP_CLI_CACHE_EXPIRY configuration - Add scenario testing WP_CLI_CACHE_MAX_SIZE configuration - Add scenario testing environment variable precedence for both - Tests verify config fallbacks and env var override behavior Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
swissspidy
reviewed
Jan 21, 2026
swissspidy
reviewed
Jan 21, 2026
Add WP_CLI_CACHE_EXPIRY and WP_CLI_CACHE_MAX_SIZE to the example configuration to showcase all environment variables that can be configured via wp-cli.yml Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Add is_array() check for $runner->config['env'] to prevent potential warnings if the env key exists but is not an array due to a malformed config file. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
- Remove 'env' from config-spec.php so it lives in extra_config (consistent with other command defaults like 'config create:') - Update get_env_or_config() to look in extra_config['env'] - Extend coverage to more WP_CLI_* env vars that are read after config is loaded: WP_CLI_AUTOCORRECT, WP_CLI_SUPPRESS_GLOBAL_PARAMS, WP_CLI_SKIP_PROMPT, WP_CLI_AUTO_UPDATE_PROMPT, WP_CLI_DISABLE_AUTO_CHECK_UPDATE, WP_CLI_AUTO_CHECK_UPDATE_DAYS, WP_CLI_SSH_PRE_CMD, WP_CLI_SSH_BINARY, WP_CLI_DOCKER_NO_TTY, WP_CLI_DOCKER_NO_INTERACTIVE, WP_CLI_ALIAS_GROUPS_PARALLEL, WP_CLI_WINDOWS_CODE_PAGE - Add Behat tests for WP_CLI_SKIP_PROMPT, WP_CLI_AUTO_UPDATE_PROMPT, WP_CLI_AUTOCORRECT - Update example YAML with all supported env vars and a note about quoting YAML boolean-like string values Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
swissspidy
added a commit
to apermo/wp-cli
that referenced
this pull request
Mar 16, 2026
…6169) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
swissspidy
added a commit
that referenced
this pull request
Mar 16, 2026
…6270) * fix(context): resolve admin user dynamically Replace hardcoded user ID 1 fallback in Admin context with smart user resolution. On multisite, queries get_super_admins() to find a valid super admin. On single site, queries for the first user with the administrator role. Emits a clear error if no suitable user is found. Fixes #6269 * fix(context): optimize query and add test cases Use get_users() with login__in for single DB query instead of looping get_user_by(). Add single-site error case test. Replace wp super-admin commands with direct option manipulation in tests. * fix(context): fix linting issues Use single quotes for strings per PHPCS rules. Fix gherkin use-and lint violations by replacing consecutive When steps with And. * fix(context): address review feedback Revert multisite super admin lookup from get_users() back to foreach + get_user_by('login') loop because get_users() only fetches users on the current site but a super admin might not be a member of any site. Add debug logging after resolving admin user ID. * fix(context): use instanceof for type safety * Fix autoloader priority: locally installed packages now fully override phar-bundled versions (#6218) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> * Add environment variable configuration support to wp-cli.yml (#6169) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> * Autocomplete `--url` (#5704) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> * Add WP-CLI handbook link to `wp help` output (#6273) * Initial plan * Add WP-CLI handbook URL reference to wp help output Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Update file(s) from wp-cli/.github * Update file(s) from wp-cli/.github * Fix SSH alias path not forwarded to remote when defined as a separate config key (#6274) * Initial plan * Fix SSH alias path not forwarded to remote when path is a separate config key Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Fix: forward active alias to runcommand subprocess (#6272) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Fix vagrant SSH strict host key checking failure (#6275) * Initial plan * Fix vagrant SSH strict host key checking failure When ssh: vagrant is configured and vagrant ssh-config is parsed, add -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null to the SSH command to match what vagrant itself sets. This prevents failures when the vagrant VM has been recreated and has a different host key than what is stored in ~/.ssh/known_hosts. Adds a Behat test scenario to verify the fix. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @swissspidy --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Add optional `$newline` parameter to `WP_CLI::log()` and `WP_CLI::line()` (#6276) * Initial plan * Add optional $newline parameter to WP_CLI::log(), WP_CLI::line(), and logger info() methods Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Undo Base class change --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> * Refactor: remove unused imports (#6277) * Harden some tests on macOS * Update tests --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Ian Dunn <ian@iandunn.name> Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-authored-by: swissspidy <swissspidy@users.noreply.github.com> Co-authored-by: Sören Wünsch <soerenwrede@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds support for configuring environment variable fallback values in
wp-cli.yml. When an environment variable is not set in the shell, WP-CLI checks the configuration file for a fallback value. Actual environment variables always take precedence.The
envkey inwp-cli.ymlis treated as extra config (consistent with other command-specific defaults likeconfig create:), not a formal config spec entry.Changes
Core implementation:
envkey inwp-cli.ymlis stored inextra_config(notconfig-spec.php) for consistency with other command defaultsWP_CLI\Utils\get_env_or_config()helper that checks environment first, then configWP_CLI_*vars that are read after config is initialized:WP_CLI_CACHE_DIR,WP_CLI_CACHE_EXPIRY,WP_CLI_CACHE_MAX_SIZEWP_CLI_PACKAGES_DIRWP_CLI_DISABLE_AUTO_CHECK_UPDATE,WP_CLI_AUTO_CHECK_UPDATE_DAYS,WP_CLI_AUTO_UPDATE_PROMPTWP_CLI_SKIP_PROMPTWP_CLI_AUTOCORRECT,WP_CLI_SUPPRESS_GLOBAL_PARAMSWP_CLI_SSH_PRE_CMD,WP_CLI_SSH_BINARY,WP_CLI_DOCKER_NO_TTY,WP_CLI_DOCKER_NO_INTERACTIVEWP_CLI_ALIAS_GROUPS_PARALLEL,WP_CLI_WINDOWS_CODE_PAGEDocumentation:
wp-cli-config.json) withenvproperty definitionwp-cli.example.ymlwith all supported environment variables and a note about quoting YAML boolean-like string valuesTests:
WP_CLI_CACHE_DIR,WP_CLI_PACKAGES_DIR,WP_CLI_CACHE_EXPIRY,WP_CLI_CACHE_MAX_SIZE,WP_CLI_SKIP_PROMPT,WP_CLI_AUTO_UPDATE_PROMPT,WP_CLI_AUTOCORRECTExample Usage
How has this been tested?
Checklist:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.