Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 2, 2025

This PR adds support for loading system-wide configuration files with cross-platform support, enabling system administrators to provide shared WP-CLI configurations for all users on Linux, macOS, and Windows.

Configuration Loading Order

The implementation establishes the following configuration priority hierarchy:

  1. System config: Platform-specific system-wide location (lowest priority)
  2. Global config: ~/.wp-cli/config.yml or WP_CLI_CONFIG_PATH (medium priority)
  3. Project config: wp-cli.yml or wp-cli.local.yml (highest priority)

Each subsequent config file can override settings from the previous ones, allowing system-wide defaults to be overridden by user-specific settings, which can be further overridden by project-specific settings.

System Config Locations

The system-wide configuration file is loaded from different locations depending on the operating system:

  • Linux: /etc/wp-cli/config.yml
  • macOS: /Library/Application Support/WP-CLI/config.yml
  • Windows: C:\ProgramData\wp-cli\config.yml (uses ProgramData environment variable if available, falls back to hardcoded path)

The path can be overridden using the WP_CLI_SYSTEM_SETTINGS_PATH environment variable.

Changes Made

Core Implementation

Runner.php:

  • Added $system_config_path and $system_config_path_debug properties
  • Added get_system_config_path() method with cross-platform OS detection
  • Support for Linux (/etc/wp-cli/config.yml), macOS (/Library/Application Support/WP-CLI/config.yml), and Windows (C:\ProgramData\wp-cli\config.yml)
  • Modified init_config() to load system config first before global and project configs
  • Added debug message output for system config status
  • Support for WP_CLI_SYSTEM_SETTINGS_PATH environment variable to override the default path

LoadRequiredCommand.php:

  • Added 'system' scope to error messages for missing required files
  • Added defensive isset() check to prevent undefined array key warnings

Testing

config.feature:

  • Added Behat test scenarios for WP_CLI_SYSTEM_SETTINGS_PATH environment variable
  • Test custom system config path and debug output verification
  • Test system config with aliases
  • Test that user config properly overrides system config settings (demonstrating priority hierarchy)

Features Enabled

This implementation enables system administrators to:

  • Provide default WP-CLI configurations for all users on Linux, macOS, and Windows
  • Define shared alias definitions across multiple user accounts
  • Set organization-wide command defaults and disabled commands
  • Centralize required file loading for custom commands
  • Override the default system config path via environment variable for flexibility

Testing Notes

The implementation gracefully handles the absence of system config files:

  • Returns false from get_system_config_path() when file doesn't exist
  • Configurator::merge_yml() safely handles false by returning empty array
  • Debug message indicates "No readable system config found"

Behat tests validate the custom WP_CLI_SYSTEM_SETTINGS_PATH functionality, including proper config loading, alias support, and config priority hierarchy.

Backwards Compatibility

This feature is fully backwards compatible with existing WP-CLI installations. When the system config file doesn't exist, WP-CLI behaves exactly as before with no performance impact or breaking changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>Load global config from /etc/wp-cli/ if it exists</issue_title>
<issue_description>Usual wp-cli global configuration lives into ~/.wp-cli where, most notably, wp-cli reads aliases.

When multiples users are intended to use wp-cli, it's convenient to manage aliases in one common place.

Environment variable like WP_CLI_CONFIG_PATH, if correctly set and exported by each user, could help, but still, this is what /etc/ is for : provide machine-wide configuration.

Couldn't wp-cli load /etc/wp-cli if it exist (and override its directives with the ones from the home-directory configuration)?</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber We can consider this for 3.0.0

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

❌ Patch coverage is 53.12500% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Runner.php 51.85% 13 Missing ⚠️
php/WP_CLI/Bootstrap/LoadRequiredCommand.php 60.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI and others added 2 commits November 2, 2025 17:29
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot AI changed the title [WIP] Load global config from /etc/wp-cli/ if it exists Load global config from /etc/wp-cli/ if it exists Nov 2, 2025
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review November 3, 2025 08:48
@swissspidy swissspidy requested a review from a team as a code owner November 3, 2025 08:48
@schlessera
Copy link
Member

@swissspidy This does not seem to take into account the efforts in other parts where we want to remove OS-specific solutions and conventions. The /etc/ folder will not exist on Windows. Not sure how this concept would translate in the Windows environment as well - a registry setting?

Note: in WSL2, this will work just fine in the Linux subsystem, I'm specifically discussing the implications for the regular Windows Command Prompt and PowerShell support.

@swissspidy
Copy link
Member

Comparing this with Gemini-CLI, which supports the following locations for system-wide configs:

Linux: /etc/gemini-cli/settings.json
Windows: C:\ProgramData\gemini-cli\settings.json
macOS: /Library/Application Support/GeminiCli/settings.json
The path can be overridden using the GEMINI_CLI_SYSTEM_SETTINGS_PATH environment variable.

We could basically do the same

@swissspidy

This comment was marked as resolved.

- Support Windows: C:\ProgramData\wp-cli\config.yml
- Support macOS: /Library/Application Support/WP-CLI/config.yml
- Support Linux: /etc/wp-cli/config.yml
- Add WP_CLI_SYSTEM_SETTINGS_PATH env var to override default path
- Use ProgramData env var on Windows, fallback to C:\ProgramData

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot AI changed the title Load global config from /etc/wp-cli/ if it exists Load system-wide config with cross-platform support Dec 11, 2025
@swissspidy

This comment was marked as resolved.

- Test custom system config path via WP_CLI_SYSTEM_SETTINGS_PATH
- Test system config with aliases
- Test that user config overrides system config
- Verify debug output shows correct config path

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load global config from /etc/wp-cli/ if it exists

4 participants