Load system-wide config with cross-platform support - #6143
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
|
@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 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. |
|
Comparing this with Gemini-CLI, which supports the following locations for system-wide configs:
We could basically do the same |
- 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.
This comment was marked as resolved.
This comment was marked as resolved.
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.
This comment was marked as resolved.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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:
~/.wp-cli/config.ymlorWP_CLI_CONFIG_PATH(medium priority)wp-cli.ymlorwp-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:
/etc/wp-cli/config.yml/Library/Application Support/WP-CLI/config.ymlC:\ProgramData\wp-cli\config.yml(usesProgramDataenvironment variable if available, falls back to hardcoded path)The path can be overridden using the
WP_CLI_SYSTEM_SETTINGS_PATHenvironment variable.Changes Made
Core Implementation
Runner.php:
$system_config_pathand$system_config_path_debugpropertiesget_system_config_path()method with cross-platform OS detection/etc/wp-cli/config.yml), macOS (/Library/Application Support/WP-CLI/config.yml), and Windows (C:\ProgramData\wp-cli\config.yml)init_config()to load system config first before global and project configsWP_CLI_SYSTEM_SETTINGS_PATHenvironment variable to override the default pathLoadRequiredCommand.php:
isset()check to prevent undefined array key warningsTesting
config.feature:
WP_CLI_SYSTEM_SETTINGS_PATHenvironment variableFeatures Enabled
This implementation enables system administrators to:
Testing Notes
The implementation gracefully handles the absence of system config files:
falsefromget_system_config_path()when file doesn't existConfigurator::merge_yml()safely handlesfalseby returning empty arrayBehat tests validate the custom
WP_CLI_SYSTEM_SETTINGS_PATHfunctionality, 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
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.