Repository: conda/conda

Issue:
Create a conda command to write default config values and info to condarc
It would be nice to have a way to materialize the whole spectrum of configuration options for conda in the user condarc (if empty).

`conda config --write-defaults` 

I guess this could also be used for other locations
`conda config --write-defaults --sytem` 

Something like:

![image](https://cloud.githubusercontent.com/assets/3627835/26373862/ce48e49a-3fc8-11e7-9fd6-80baccfeb145.png)





Discussion:

Resolving patch:
diff --git a/conda/cli/main_config.py b/conda/cli/main_config.py
--- a/conda/cli/main_config.py
+++ b/conda/cli/main_config.py
@@ -9,7 +9,7 @@
 import collections
 import json
 import os
-from os.path import join
+from os.path import isfile, join
 import sys
 from textwrap import wrap
 
@@ -138,6 +138,13 @@ def configure_parser(sub_parsers):
         action="store_true",
         help="Describe available configuration parameters.",
     )
+    action.add_argument(
+        "--write-default",
+        action="store_true",
+        help="Write the default configuration to a file. "
+             "Equivalent to `conda config --describe > ~/.condarc` "
+             "when no --env, --system, or --file flags are given.",
+    )
     action.add_argument(
         "--get",
         nargs='*',
@@ -231,12 +238,45 @@ def format_dict(d):
     return lines
 
 
+def parameter_description_builder(name):
+    from .._vendor.auxlib.entity import EntityEncoder
+    builder = []
+    details = context.describe_parameter(name)
+    aliases = details['aliases']
+    string_delimiter = details.get('string_delimiter')
+    element_types = details['element_types']
+    default_value_str = json.dumps(details['default_value'], cls=EntityEncoder)
+
+    if details['parameter_type'] == 'primitive':
+        builder.append("%s (%s)" % (name, ', '.join(sorted(set(et for et in element_types)))))
+    else:
+        builder.append("%s (%s: %s)" % (name, details['parameter_type'],
+                                        ', '.join(sorted(set(et for et in element_types)))))
+
+    if aliases:
+        builder.append("  aliases: %s" % ', '.join(aliases))
+    if string_delimiter:
+        builder.append("  string delimiter: '%s'" % string_delimiter)
+
+    builder.extend('  ' + line for line in wrap(details['description'], 70))
+
+    builder.append('')
+
+    builder.extend(yaml_dump({name: json.loads(default_value_str)}).strip().split('\n'))
+
+    builder = ['# ' + line for line in builder]
+    builder.append('')
+    builder.append('')
+    return builder
+
+
 def execute_config(args, parser):
     try:
-        from cytoolz.itertoolz import groupby
+        from cytoolz.itertoolz import concat, groupby
     except ImportError:  # pragma: no cover
-        from .._vendor.toolz.itertoolz import groupby  # NOQA
+        from .._vendor.toolz.itertoolz import concat, groupby  # NOQA
     from .._vendor.auxlib.entity import EntityEncoder
+
     json_warnings = []
     json_get = {}
 
@@ -280,26 +320,8 @@ def execute_config(args, parser):
                              sort_keys=True, indent=2, separators=(',', ': '),
                              cls=EntityEncoder))
         else:
-            for name in paramater_names:
-                details = context.describe_parameter(name)
-                aliases = details['aliases']
-                string_delimiter = details.get('string_delimiter')
-                element_types = details['element_types']
-                if details['parameter_type'] == 'primitive':
-                    print("%s (%s)" % (name, ', '.join(sorted(set(et for et in element_types)))))
-                else:
-                    print("%s (%s: %s)" % (name, details['parameter_type'],
-                                           ', '.join(sorted(set(et for et in element_types)))))
-                def_str = '  default: %s' % json.dumps(details['default_value'], indent=2,
-                                                       separators=(',', ': '),
-                                                       cls=EntityEncoder)
-                print('\n  '.join(def_str.split('\n')))
-                if aliases:
-                    print("  aliases: %s" % ', '.join(aliases))
-                if string_delimiter:
-                    print("  string delimiter: '%s'" % string_delimiter)
-                print('\n  '.join(wrap('  ' + details['description'], 70)))
-                print()
+            print('\n'.join(concat(parameter_description_builder(name)
+                                   for name in paramater_names)))
         return
 
     if args.validate:
@@ -318,6 +340,23 @@ def execute_config(args, parser):
     else:
         rc_path = user_rc_path
 
+    if args.write_default:
+        if isfile(rc_path):
+            with open(rc_path) as fh:
+                data = fh.read().strip()
+            if data:
+                raise CondaError("The file '%s' "
+                                 "already contains configuration information.\n"
+                                 "Remove the file to proceed.\n"
+                                 "Use `conda config --describe` to display default configuration."
+                                 % rc_path)
+
+        with open(rc_path, 'w') as fh:
+            paramater_names = context.list_parameters()
+            fh.write('\n'.join(concat(parameter_description_builder(name)
+                                      for name in paramater_names)))
+        return
+
     # read existing condarc
     if os.path.exists(rc_path):
         with open(rc_path, 'r') as fh:


Test patch:
diff --git a/tests/test_create.py b/tests/test_create.py
--- a/tests/test_create.py
+++ b/tests/test_create.py
@@ -610,7 +610,7 @@ def test_conda_config_describe(self):
             stdout, stderr = run_command(Commands.CONFIG, prefix, "--describe")
             assert not stderr
             for param_name in context.list_parameters():
-                assert re.search(r'^%s \(' % param_name, stdout, re.MULTILINE)
+                assert re.search(r'^# %s \(' % param_name, stdout, re.MULTILINE)
 
             stdout, stderr = run_command(Commands.CONFIG, prefix, "--describe --json")
             assert not stderr
@@ -629,6 +629,19 @@ def test_conda_config_describe(self):
                 assert json_obj['envvars'] == {'quiet': True}
                 assert json_obj['cmd_line'] == {'json': True}
 
+            run_command(Commands.CONFIG, prefix, "--set changeps1 false")
+            with pytest.raises(CondaError):
+                run_command(Commands.CONFIG, prefix, "--write-default")
+
+            rm_rf(join(prefix, 'condarc'))
+            run_command(Commands.CONFIG, prefix, "--write-default")
+
+            with open(join(prefix, 'condarc')) as fh:
+                data = fh.read()
+
+            for param_name in context.list_parameters():
+                assert re.search(r'^# %s \(' % param_name, data, re.MULTILINE)
+
     def test_conda_config_validate(self):
         with make_temp_env() as prefix:
             run_command(Commands.CONFIG, prefix, "--set ssl_verify no")