prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  config: add --list to list all variables and their values
  Something that would be handy for us during debugging and for users. Same as `git config --list`. Useful to avoid confusion such as in https://github.com/iterative/dvc/issues/4970
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `dvc/command/config.py`
  Content:
  ```
  1 import argparse
  2 import logging
  3 
  4 from dvc.command.base import CmdBaseNoRepo, append_doc_link
  5 from dvc.config import Config, ConfigError
  6 
  7 logger = logging.getLogger(__name__)
  8 
  9 
  10 class CmdConfig(CmdBaseNoRepo):
  11     def __init__(self, args):
  12         super().__init__(args)
  13 
  14         self.config = Config(validate=False)
  15 
  16     def run(self):
  17         section, opt = self.args.name.lower().strip().split(".", 1)
  18 
  19         if self.args.value is None and not self.args.unset:
  20             conf = self.config.load_one(self.args.level)
  21             self._check(conf, section, opt)
  22             logger.info(conf[section][opt])
  23             return 0
  24 
  25         with self.config.edit(self.args.level) as conf:
  26             if self.args.unset:
  27                 self._check(conf, section, opt)
  28                 del conf[section][opt]
  29             else:
  30                 self._check(conf, section)
  31                 conf[section][opt] = self.args.value
  32 
  33         if self.args.name == "cache.type":
  34             logger.warning(
  35                 "You have changed the 'cache.type' option. This doesn't update"
  36                 " any existing workspace file links, but it can be done with:"
  37                 "\n             dvc checkout --relink"
  38             )
  39 
  40         return 0
  41 
  42     def _check(self, conf, section, opt=None):
  43         if section not in conf:
  44             msg = "section {} doesn't exist"
  45             raise ConfigError(msg.format(self.args.name))
  46 
  47         if opt and opt not in conf[section]:
  48             msg = "option {} doesn't exist"
  49             raise ConfigError(msg.format(self.args.name))
  50 
  51 
  52 parent_config_parser = argparse.ArgumentParser(add_help=False)
  53 level_group = parent_config_parser.add_mutually_exclusive_group()
  54 level_group.add_argument(
  55     "--global",
  56     dest="level",
  57     action="store_const",
  58     const="global",
  59     help="Use global config.",
  60 )
  61 level_group.add_argument(
  62     "--system",
  63     dest="level",
  64     action="store_const",
  65     const="system",
  66     help="Use system config.",
  67 )
  68 level_group.add_argument(
  69     "--local",
  70     dest="level",
  71     action="store_const",
  72     const="local",
  73     help="Use local config.",
  74 )
  75 parent_config_parser.set_defaults(level="repo")
  76 
  77 
  78 def add_parser(subparsers, parent_parser):
  79     CONFIG_HELP = "Get or set config options."
  80 
  81     config_parser = subparsers.add_parser(
  82         "config",
  83         parents=[parent_config_parser, parent_parser],
  84         description=append_doc_link(CONFIG_HELP, "config"),
  85         help=CONFIG_HELP,
  86         formatter_class=argparse.RawDescriptionHelpFormatter,
  87     )
  88     config_parser.add_argument(
  89         "-u",
  90         "--unset",
  91         default=False,
  92         action="store_true",
  93         help="Unset option.",
  94     )
  95     config_parser.add_argument("name", help="Option name.")
  96     config_parser.add_argument("value", nargs="?", help="Option value.")
  97     config_parser.set_defaults(func=CmdConfig)
  98
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/dvc/command/config.py b/dvc/command/config.py
  --- a/dvc/command/config.py
  +++ b/dvc/command/config.py
  @@ -3,6 +3,7 @@
   
   from dvc.command.base import CmdBaseNoRepo, append_doc_link
   from dvc.config import Config, ConfigError
  +from dvc.utils.flatten import flatten
   
   logger = logging.getLogger(__name__)
   
  @@ -14,6 +15,22 @@
           self.config = Config(validate=False)
   
       def run(self):
  +        if self.args.list:
  +            if any((self.args.name, self.args.value, self.args.unset)):
  +                logger.error(
  +                    "-l/--list can't be used together with any of these "
  +                    "options: -u/--unset, name, value"
  +                )
  +                return 1
  +
  +            conf = self.config.load_one(self.args.level)
  +            logger.info("\n".join(self._format_config(conf)))
  +            return 0
  +
  +        if self.args.name is None:
  +            logger.error("name argument is required")
  +            return 1
  +
           section, opt = self.args.name.lower().strip().split(".", 1)
   
           if self.args.value is None and not self.args.unset:
  @@ -48,6 +65,11 @@
               msg = "option {} doesn't exist"
               raise ConfigError(msg.format(self.args.name))
   
  +    @staticmethod
  +    def _format_config(config):
  +        for key, value in flatten(config).items():
  +            yield f"{key}={value}"
  +
   
   parent_config_parser = argparse.ArgumentParser(add_help=False)
   level_group = parent_config_parser.add_mutually_exclusive_group()
  @@ -92,6 +114,13 @@
           action="store_true",
           help="Unset option.",
       )
  -    config_parser.add_argument("name", help="Option name.")
  +    config_parser.add_argument("name", nargs="?", help="Option name.")
       config_parser.add_argument("value", nargs="?", help="Option value.")
  +    config_parser.add_argument(
  +        "-l",
  +        "--list",
  +        default=False,
  +        action="store_true",
  +        help="list all defined config values",
  +    )
       config_parser.set_defaults(func=CmdConfig)
  
verification_info: {"golden_diff": "diff --git a/dvc/command/config.py b/dvc/command/config.py\n--- a/dvc/command/config.py\n+++ b/dvc/command/config.py\n@@ -3,6 +3,7 @@\n \n from dvc.command.base import CmdBaseNoRepo, append_doc_link\n from dvc.config import Config, ConfigError\n+from dvc.utils.flatten import flatten\n \n logger = logging.getLogger(__name__)\n \n@@ -14,6 +15,22 @@\n         self.config = Config(validate=False)\n \n     def run(self):\n+        if self.args.list:\n+            if any((self.args.name, self.args.value, self.args.unset)):\n+                logger.error(\n+                    \"-l/--list can't be used together with any of these \"\n+                    \"options: -u/--unset, name, value\"\n+                )\n+                return 1\n+\n+            conf = self.config.load_one(self.args.level)\n+            logger.info(\"\\n\".join(self._format_config(conf)))\n+            return 0\n+\n+        if self.args.name is None:\n+            logger.error(\"name argument is required\")\n+            return 1\n+\n         section, opt = self.args.name.lower().strip().split(\".\", 1)\n \n         if self.args.value is None and not self.args.unset:\n@@ -48,6 +65,11 @@\n             msg = \"option {} doesn't exist\"\n             raise ConfigError(msg.format(self.args.name))\n \n+    @staticmethod\n+    def _format_config(config):\n+        for key, value in flatten(config).items():\n+            yield f\"{key}={value}\"\n+\n \n parent_config_parser = argparse.ArgumentParser(add_help=False)\n level_group = parent_config_parser.add_mutually_exclusive_group()\n@@ -92,6 +114,13 @@\n         action=\"store_true\",\n         help=\"Unset option.\",\n     )\n-    config_parser.add_argument(\"name\", help=\"Option name.\")\n+    config_parser.add_argument(\"name\", nargs=\"?\", help=\"Option name.\")\n     config_parser.add_argument(\"value\", nargs=\"?\", help=\"Option value.\")\n+    config_parser.add_argument(\n+        \"-l\",\n+        \"--list\",\n+        default=False,\n+        action=\"store_true\",\n+        help=\"list all defined config values\",\n+    )\n     config_parser.set_defaults(func=CmdConfig)\n", "issue": "config: add --list to list all variables and their values\nSomething that would be handy for us during debugging and for users. Same as `git config --list`. Useful to avoid confusion such as in https://github.com/iterative/dvc/issues/4970\n", "before_files": [{"content": "import argparse\nimport logging\n\nfrom dvc.command.base import CmdBaseNoRepo, append_doc_link\nfrom dvc.config import Config, ConfigError\n\nlogger = logging.getLogger(__name__)\n\n\nclass CmdConfig(CmdBaseNoRepo):\n    def __init__(self, args):\n        super().__init__(args)\n\n        self.config = Config(validate=False)\n\n    def run(self):\n        section, opt = self.args.name.lower().strip().split(\".\", 1)\n\n        if self.args.value is None and not self.args.unset:\n            conf = self.config.load_one(self.args.level)\n            self._check(conf, section, opt)\n            logger.info(conf[section][opt])\n            return 0\n\n        with self.config.edit(self.args.level) as conf:\n            if self.args.unset:\n                self._check(conf, section, opt)\n                del conf[section][opt]\n            else:\n                self._check(conf, section)\n                conf[section][opt] = self.args.value\n\n        if self.args.name == \"cache.type\":\n            logger.warning(\n                \"You have changed the 'cache.type' option. This doesn't update\"\n                \" any existing workspace file links, but it can be done with:\"\n                \"\\n             dvc checkout --relink\"\n            )\n\n        return 0\n\n    def _check(self, conf, section, opt=None):\n        if section not in conf:\n            msg = \"section {} doesn't exist\"\n            raise ConfigError(msg.format(self.args.name))\n\n        if opt and opt not in conf[section]:\n            msg = \"option {} doesn't exist\"\n            raise ConfigError(msg.format(self.args.name))\n\n\nparent_config_parser = argparse.ArgumentParser(add_help=False)\nlevel_group = parent_config_parser.add_mutually_exclusive_group()\nlevel_group.add_argument(\n    \"--global\",\n    dest=\"level\",\n    action=\"store_const\",\n    const=\"global\",\n    help=\"Use global config.\",\n)\nlevel_group.add_argument(\n    \"--system\",\n    dest=\"level\",\n    action=\"store_const\",\n    const=\"system\",\n    help=\"Use system config.\",\n)\nlevel_group.add_argument(\n    \"--local\",\n    dest=\"level\",\n    action=\"store_const\",\n    const=\"local\",\n    help=\"Use local config.\",\n)\nparent_config_parser.set_defaults(level=\"repo\")\n\n\ndef add_parser(subparsers, parent_parser):\n    CONFIG_HELP = \"Get or set config options.\"\n\n    config_parser = subparsers.add_parser(\n        \"config\",\n        parents=[parent_config_parser, parent_parser],\n        description=append_doc_link(CONFIG_HELP, \"config\"),\n        help=CONFIG_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    config_parser.add_argument(\n        \"-u\",\n        \"--unset\",\n        default=False,\n        action=\"store_true\",\n        help=\"Unset option.\",\n    )\n    config_parser.add_argument(\"name\", help=\"Option name.\")\n    config_parser.add_argument(\"value\", nargs=\"?\", help=\"Option value.\")\n    config_parser.set_defaults(func=CmdConfig)\n", "path": "dvc/command/config.py"}], "after_files": [{"content": "import argparse\nimport logging\n\nfrom dvc.command.base import CmdBaseNoRepo, append_doc_link\nfrom dvc.config import Config, ConfigError\nfrom dvc.utils.flatten import flatten\n\nlogger = logging.getLogger(__name__)\n\n\nclass CmdConfig(CmdBaseNoRepo):\n    def __init__(self, args):\n        super().__init__(args)\n\n        self.config = Config(validate=False)\n\n    def run(self):\n        if self.args.list:\n            if any((self.args.name, self.args.value, self.args.unset)):\n                logger.error(\n                    \"-l/--list can't be used together with any of these \"\n                    \"options: -u/--unset, name, value\"\n                )\n                return 1\n\n            conf = self.config.load_one(self.args.level)\n            logger.info(\"\\n\".join(self._format_config(conf)))\n            return 0\n\n        if self.args.name is None:\n            logger.error(\"name argument is required\")\n            return 1\n\n        section, opt = self.args.name.lower().strip().split(\".\", 1)\n\n        if self.args.value is None and not self.args.unset:\n            conf = self.config.load_one(self.args.level)\n            self._check(conf, section, opt)\n            logger.info(conf[section][opt])\n            return 0\n\n        with self.config.edit(self.args.level) as conf:\n            if self.args.unset:\n                self._check(conf, section, opt)\n                del conf[section][opt]\n            else:\n                self._check(conf, section)\n                conf[section][opt] = self.args.value\n\n        if self.args.name == \"cache.type\":\n            logger.warning(\n                \"You have changed the 'cache.type' option. This doesn't update\"\n                \" any existing workspace file links, but it can be done with:\"\n                \"\\n             dvc checkout --relink\"\n            )\n\n        return 0\n\n    def _check(self, conf, section, opt=None):\n        if section not in conf:\n            msg = \"section {} doesn't exist\"\n            raise ConfigError(msg.format(self.args.name))\n\n        if opt and opt not in conf[section]:\n            msg = \"option {} doesn't exist\"\n            raise ConfigError(msg.format(self.args.name))\n\n    @staticmethod\n    def _format_config(config):\n        for key, value in flatten(config).items():\n            yield f\"{key}={value}\"\n\n\nparent_config_parser = argparse.ArgumentParser(add_help=False)\nlevel_group = parent_config_parser.add_mutually_exclusive_group()\nlevel_group.add_argument(\n    \"--global\",\n    dest=\"level\",\n    action=\"store_const\",\n    const=\"global\",\n    help=\"Use global config.\",\n)\nlevel_group.add_argument(\n    \"--system\",\n    dest=\"level\",\n    action=\"store_const\",\n    const=\"system\",\n    help=\"Use system config.\",\n)\nlevel_group.add_argument(\n    \"--local\",\n    dest=\"level\",\n    action=\"store_const\",\n    const=\"local\",\n    help=\"Use local config.\",\n)\nparent_config_parser.set_defaults(level=\"repo\")\n\n\ndef add_parser(subparsers, parent_parser):\n    CONFIG_HELP = \"Get or set config options.\"\n\n    config_parser = subparsers.add_parser(\n        \"config\",\n        parents=[parent_config_parser, parent_parser],\n        description=append_doc_link(CONFIG_HELP, \"config\"),\n        help=CONFIG_HELP,\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n    )\n    config_parser.add_argument(\n        \"-u\",\n        \"--unset\",\n        default=False,\n        action=\"store_true\",\n        help=\"Unset option.\",\n    )\n    config_parser.add_argument(\"name\", nargs=\"?\", help=\"Option name.\")\n    config_parser.add_argument(\"value\", nargs=\"?\", help=\"Option value.\")\n    config_parser.add_argument(\n        \"-l\",\n        \"--list\",\n        default=False,\n        action=\"store_true\",\n        help=\"list all defined config values\",\n    )\n    config_parser.set_defaults(func=CmdConfig)\n", "path": "dvc/command/config.py"}]}