Refactor various path-related helper functions into a `Path` class
We have more and more path-related helper functions that are spread across the code. When looking into #5005, I remembered previous code I had already worked on and even spent a considerable amount of time hunting for the actual code until I found it in the wp-cli/scaffold-command package.
I want to refactor this in the following way:
-
[ ] Provide a
Pathclass in the framework that takes all of these little helpers and puts them in one place.Pathcould be modeled after https://github.com/webmozart/path-util (which Drush uses), but as we need additional custom helpers as well, I'd prefer to not pull in yet another dependency and just copy what we need. -
[ ] Switch the helper functions to be
@deprecatedand just forward the call to the correspondingPathmethod instead. -
[ ] Replace calls to the helper functions, and make the packages that have done so rely on the minimum version of the framework that comes with
Path.
This will hopefully make it easier to maintain these, make them less error-prone (as based on reference code), and make it more obvious to use them throughout all of the path-handling so that behavior becomes consistent across packages.
Hi there,
Per @danielbachhuber's suggestion, below are conceptual questions mentioned in #5695 (a closed pull request):
- Will tildes be supported in WP CLI paths both in config file references such as the argument to
inheritand thepathargument in wp cli alias definitions on the local computer (those without ansshproperty)? - Will relative paths for local and remote wp cli aliases be relative to the user's home directory (on the local or remote machine)? If not, how will this be resolved? If they will be relative to the user's home directory, then users can omit a tilde in alias definitions, obviating the need for them as stated in the previous question. This is the case for remote aliases now. For local aliases (those without the
sshproperty), this is not the case. For local aliases, relative paths are relative to the path of the config file that defines them. This may be confusing (though desirable?) for those who have multiple config files in different directories. Example:
In /Users/saul/.wp-cli/config.yml:
@alias1:
path: Sites/example1.org
_:
inherit: /Users/saul/.other-config.yml
And in /Users/saul/.other-config.yml:
@alias2:
path: Sites/example2.org
The paths become...
alias1: /Users/saul/.wp-cli/Sites/example1.org
alias2: /Users/saul/Sites/example2.org
Maybe this is just an argument to support the tilde character for local aliases so that the path values can specify the correct path regardless of what file defines them.