Repository: dbt-labs/dbt-core

Issue:
dbt init --adapter default to the available adapter
### Describe the bug
In v0.18+, `dbt init` takes an additional argument `--adapter` so as to generate `profiles.yml` according to the adapter type specified.

### Steps To Reproduce
Fresh install of a non-core plugin:
```
pip install dbt-spark
```
Initialize a project:
```
$ dbt init my_project
Running with dbt=0.18.0
Creating dbt configuration folder at /Users/jerco/.dbt
With sample profiles.yml for redshift
Encountered an error:
Runtime Error
  Could not find adapter type redshift!
```

### Expected behavior
The `--adapter` argument should check the adapters available in the context

### System information
**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [ ] bigquery
- [ ] snowflake
- [x] other (any community-contrib plugin)


**The output of `dbt --version`:**
```
dbt --version
installed version: 0.18.0
   latest version: 0.18.0

Up to date!

Plugins:
  - spark: 0.18.0
```



Discussion:
Another issue: If the adapter plugin doesn't define a sample `profiles.yml`, dbt doesn't allow the user to run `dbt init`. Instead, dbt should fall back to a generic one, or do _anything_ smarter than disallowing use of the `init` command entirely (cc @amychen1776).
Copying from #3434:

> If the `--adapter` argument is not passed, I think our options are:
> - `init` checks the adapters available, rather than falling back to `redshift` as the default
> - `init` falls back to a more reasonable, generic default (not `redshift`) that ships inside of `core`

Resolving patch:
diff --git a/core/dbt/main.py b/core/dbt/main.py
--- a/core/dbt/main.py
+++ b/core/dbt/main.py
@@ -367,7 +367,6 @@ def _build_init_subparser(subparsers, base_subparser):
     )
     sub.add_argument(
         '--adapter',
-        default='redshift',
         type=str,
         help='''
         Write sample profiles.yml for which adapter
diff --git a/core/dbt/task/init.py b/core/dbt/task/init.py
--- a/core/dbt/task/init.py
+++ b/core/dbt/task/init.py
@@ -3,8 +3,8 @@
 
 import dbt.config
 import dbt.clients.system
+from dbt.version import _get_adapter_plugin_names
 from dbt.adapters.factory import load_plugin, get_include_paths
-from dbt.exceptions import RuntimeException
 
 from dbt.logger import GLOBAL_LOGGER as logger
 
@@ -13,14 +13,14 @@
 from dbt.task.base import BaseTask
 
 DOCS_URL = 'https://docs.getdbt.com/docs/configure-your-profile'
+SLACK_URL = 'https://community.getdbt.com/'
 
 # This file is not needed for the starter project but exists for finding the resource path
 IGNORE_FILE = "__init__.py"
 
 ON_COMPLETE_MESSAGE = """
 Your new dbt project "{project_name}" was created! If this is your first time
-using dbt, you'll need to set up your profiles.yml file (we've created a sample
-file for you to connect to {sample_adapter}) -- this file will tell dbt how
+using dbt, you'll need to set up your profiles.yml file -- this file will tell dbt how
 to connect to your database. You can find this file by running:
 
   {open_cmd} {profiles_path}
@@ -32,8 +32,11 @@
 
 One more thing:
 
-Need help? Don't hesitate to reach out to us via GitHub issues or on Slack --
-There's a link to our Slack group in the GitHub Readme. Happy modeling!
+Need help? Don't hesitate to reach out to us via GitHub issues or on Slack:
+
+  {slack_url}
+
+Happy modeling!
 """
 
 
@@ -45,6 +48,8 @@ def copy_starter_repo(self, project_name):
 
     def create_profiles_dir(self, profiles_dir):
         if not os.path.exists(profiles_dir):
+            msg = "Creating dbt configuration folder at {}"
+            logger.info(msg.format(profiles_dir))
             dbt.clients.system.make_directory(profiles_dir)
             return True
         return False
@@ -56,40 +61,44 @@ def create_profiles_file(self, profiles_file, sample_adapter):
         sample_profiles_path = adapter_path / 'sample_profiles.yml'
 
         if not sample_profiles_path.exists():
-            raise RuntimeException(f'No sample profile for {sample_adapter}')
+            logger.debug(f"No sample profile found for {sample_adapter}, skipping")
+            return False
 
         if not os.path.exists(profiles_file):
+            msg = "With sample profiles.yml for {}"
+            logger.info(msg.format(sample_adapter))
             shutil.copyfile(sample_profiles_path, profiles_file)
             return True
 
         return False
 
-    def get_addendum(self, project_name, profiles_path, sample_adapter):
+    def get_addendum(self, project_name, profiles_path):
         open_cmd = dbt.clients.system.open_dir_cmd()
 
         return ON_COMPLETE_MESSAGE.format(
             open_cmd=open_cmd,
             project_name=project_name,
-            sample_adapter=sample_adapter,
             profiles_path=profiles_path,
-            docs_url=DOCS_URL
+            docs_url=DOCS_URL,
+            slack_url=SLACK_URL
         )
 
     def run(self):
         project_dir = self.args.project_name
         sample_adapter = self.args.adapter
+        if not sample_adapter:
+            try:
+                # pick first one available, often postgres
+                sample_adapter = next(_get_adapter_plugin_names())
+            except StopIteration:
+                logger.debug("No adapters installed, skipping")
 
         profiles_dir = dbt.config.PROFILES_DIR
         profiles_file = os.path.join(profiles_dir, 'profiles.yml')
 
-        msg = "Creating dbt configuration folder at {}"
-        logger.info(msg.format(profiles_dir))
-
-        msg = "With sample profiles.yml for {}"
-        logger.info(msg.format(sample_adapter))
-
         self.create_profiles_dir(profiles_dir)
-        self.create_profiles_file(profiles_file, sample_adapter)
+        if sample_adapter:
+            self.create_profiles_file(profiles_file, sample_adapter)
 
         if os.path.exists(project_dir):
             raise RuntimeError("directory {} already exists!".format(
@@ -98,5 +107,5 @@ def run(self):
 
         self.copy_starter_repo(project_dir)
 
-        addendum = self.get_addendum(project_dir, profiles_dir, sample_adapter)
+        addendum = self.get_addendum(project_dir, profiles_dir)
         logger.info(addendum)


Test patch: