Create a default global config file if it does not exist by thrijith · Pull Request #5411 · wp-cli/wp-cli

@thrijith

Fixes #5327

  • Creates a global config path in default path if one doesn't exist already.

@thrijith

@thrijith

@schlessera The change is to handle the case when the default config doesn't exist and isn't set by WP_CLI_CONFIG_PATH.

The change creates a file by default if it doesn't exist at home directory, should the function get_global_config_path accept a parameter to handle creation?

@thrijith

@thrijith

schlessera

@schlessera

The change creates a file by default if it doesn't exist at home directory, should the function get_global_config_path accept a parameter to handle creation?

You mean to skip creating a default one? I don't think that would be needed. Worst case if you want to avoid populating the user home folders with these files, you could always point WP_CLI_CONFIG_PATH to an existing empty file or something.

schlessera

schlessera

Choose a reason for hiding this comment

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

Just thinking now that we should actually only create the file when we try to write something in there.

Otherwise, we're cloaking the fact that there is no configuration yet.

@thrijith

@schlessera The change is to handle the case when the default config doesn't exist and isn't set by WP_CLI_CONFIG_PATH.

The change creates a file by default if it doesn't exist at home directory, should the function get_global_config_path accept a parameter to handle creation?

Just thinking now that we should actually only create the file when we try to write something in there.
Otherwise, we're cloaking the fact that there is no configuration yet.

@schlessera That is what I thought initially so that it doesn't affect other commands flow create a file only when asked so we can add param in this function and when someone uses _alias add or update create one?

@schlessera

Yes, I think that's better. Commands can individually request whether the file should be created on-demand or not.

@thrijith

@thrijith

@thrijith

schlessera

Co-authored-by: Alain Schlesser <alain.schlesser@gmail.com>
Co-authored-by: Alain Schlesser <alain.schlesser@gmail.com>

@schlessera

I think the failing test is because:

  • We don't use WPCLI_CONFIG_PATH to point the global config to a path that is controlled (and thus reset) by Behat. Instead, it uses a path that is shared by all tests: Using default global config: /tmp/wp-cli-home/.wp-cli/config.yml (0.029s)
  • The aliases.features runs before these, so that creates a global config in this shared location.

@schlessera

I think this might be something we should fix in wp-cli/wp-cli-tests, redirecting the global config location into a folder that is separate per run.

schlessera

@schlessera

@schlessera

@schlessera

Trying an easier solution for now: removing existing config files in this particular test before each run.

@schlessera

Hmm, the $HOME variable is not being replaced, unfortunately. I'll have to adapt wp-cli/wp-cli-tests either way.

@schlessera

@schlessera

@schlessera