andreascreten/wp-cli — Issue #76: Per project config
Author: PerWiklander
Created: 2012-03-01 18:20:29+00:00
State: open

This issue is suggesting the possibility to have a `.wp-cli` file in the **project root** to set some default config params.

TLDR: make it possible to run `wp-cli` anywhere and not just in the wordpress directory.

## Background

When doing WordPress projects I usually have a directory layout like this:

```
git_repos_root
doc	// customer documentation
public_html // The actual document root
tools // various utilities that I create during the development
xhtml // page mockups and things like that
```

Then the content of public_html:

```
public_html
assets // What usually is /wp-content/uploads
custom // What usually is /wp-content (minus the uploads dir)
wordpress // A clean (write protected) checkout from WordPress svn.

index.php
wp-config.php
```
This works just fine with some tweaks to wp-config.php. The one needed for `wp-cli` is

```
if ( WP_CLI ) {
define( 'WP_CONTENT_DIR', dirname( getcwd() ) . '/custom' );
}
```
**But** I still have to run the `wp-cli` command in the wordpress directory for it to work

## Suggested changes

I don't want to force this directory layout onto anyone, that's not the issue here. What I would like is the possibility to have a `.wp-cli` file that specifies some of the input params:

```
document_root=public_html
wordpress_install=public_html/wordpress
site_name=My new WP site
site_url=http://www.example.com
database_name=db
user=db_user
user_pass=db_user_pass
...
```

Where the most important ones are `document_root=public_html`
and `wordpress_install=public_html/wordpress` (those paths are then relative to the directory in which `.wp-cli` is located). I would like `wp-cli` to locate this config file by first looking in the current directory and then one step up, recursively. Just like I am imagining that git is doing to be able to find the .git directory when I run the `git` command in any directory in a repos.

This would of course be totally optional, if the file is not found `wp-cli` can use the current lookup to try to find `wp-load.php`

## Benefits

The thing that made me think of this first was that my commandline now often looks like `wordpress $ wp-cli eval-file ../../tools/some-tool.php` when it could be `tools $ wp-cli eval-file some-tool.php`.

But I guess a more interesting thing would be to

1. Create an empty git repos
2. Create a `.wp-cli` file with your settings
3. Run `wp-cli new`
4. Magic happens, that is, WordPress is downloaded (latest or version specified in `.wp-cli`) and installed according to settings.

An other thing would be to allow `wp-cli db` to run even if WordPress is broken.