Repository: dbt-labs/dbt-core

Issue:
dbt clean does not respect the project-dir if provided
### Describe the bug

If I am not in the project directory and run `dbt clean --project-dir <path>`. DBT won't clean the directories starting from the project directory. It cleans it from the current directory.

### Steps To Reproduce

go out of the project directory and pass the path to directory to the `--project-dir` flag.
```
dbt clean --project-dir <path>
```

### Expected behavior

I expect dbt to clean the directories recursively defined in `clean-targets` of `dbt_project.yml`.

### System information
**Which database are you using dbt with?**
- [x] postgres
- [ ] redshift
- [ ] bigquery
- [ ] snowflake
- [ ] other (specify: ____________)


**The output of `dbt --version`:**
```
installed version: 0.18.0
   latest version: 0.18.1

Your version of dbt is out of date! You can find instructions for upgrading here:
https://docs.getdbt.com/docs/installation

Plugins:
  - bigquery: 0.18.0
  - snowflake: 0.18.0
  - redshift: 0.18.0
  - postgres: 0.18.0
```

**The operating system you're using:** macOS 10.15.6

**The output of `python --version`:** Python 3.7.2



Discussion:
Good find, @feluelle! I'm not sure if this has worked in the past, but I agree it's the intended (and expected) behavior.

I'm hopeful that this would be a straightforward fix, involving the addition of [`move_to_nearest_project_directory`](https://github.com/fishtown-analytics/dbt/blob/dev/kiyoshi-kuromiya/core/dbt/task/base.py#L141) to the [clean task](https://github.com/fishtown-analytics/dbt/blob/dev/kiyoshi-kuromiya/core/dbt/task/clean.py). The contributor should also look to add a test [here](https://github.com/fishtown-analytics/dbt/blob/dev/kiyoshi-kuromiya/test/integration/015_cli_invocation_tests/test_cli_invocation.py#L166).

Is this something you'd be interested in contributing?
Yes, I would love to work on that @jtcohen6 :)

Resolving patch:
diff --git a/core/dbt/task/clean.py b/core/dbt/task/clean.py
--- a/core/dbt/task/clean.py
+++ b/core/dbt/task/clean.py
@@ -2,7 +2,7 @@
 import os
 import shutil
 
-from dbt.task.base import BaseTask
+from dbt.task.base import BaseTask, move_to_nearest_project_dir
 from dbt.logger import GLOBAL_LOGGER as logger
 from dbt.config import UnsetProfileConfig
 
@@ -32,6 +32,7 @@ def run(self):
         This function takes all the paths in the target file
         and cleans the project paths that are not protected.
         """
+        move_to_nearest_project_dir(self.args)
         for path in self.config.clean_targets:
             logger.info("Checking {}/*".format(path))
             if not self.__is_protected_path(path):


Test patch:
diff --git a/test/integration/015_cli_invocation_tests/test_cli_invocation.py b/test/integration/015_cli_invocation_tests/test_cli_invocation.py
--- a/test/integration/015_cli_invocation_tests/test_cli_invocation.py
+++ b/test/integration/015_cli_invocation_tests/test_cli_invocation.py
@@ -168,3 +168,7 @@ def _run_simple_dbt_commands(self, project_dir):
         self.run_dbt(['seed', '--project-dir', project_dir])
         self.run_dbt(['run', '--project-dir', project_dir])
         self.run_dbt(['test', '--project-dir', project_dir])
+        self.run_dbt(['clean', '--project-dir', project_dir])
+        # In case of 'dbt clean' also test that the clean-targets directories were deleted.
+        for target in self.config.clean_targets:
+            assert not os.path.isdir(target)