We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
spack extensions behavior when no extendable package is specified
If you run `spack extensions` with no extendable package, it prints an error message telling you that a package spec is required. It would be nice if Spack also printed a list of installed extendable packages to choose from.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/spack/spack/cmd/extensions.py`
Content:
```
1 # Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
2 # Spack Project Developers. See the top-level COPYRIGHT file for details.
3 #
4 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
5 
6 import argparse
7 
8 import llnl.util.tty as tty
9 from llnl.util.tty.colify import colify
10 
11 import spack.environment as ev
12 import spack.cmd as cmd
13 import spack.cmd.common.arguments as arguments
14 import spack.repo
15 import spack.store
16 from spack.filesystem_view import YamlFilesystemView
17 
18 description = "list extensions for package"
19 section = "extensions"
20 level = "long"
21 
22 
23 def setup_parser(subparser):
24     arguments.add_common_arguments(subparser, ['long', 'very_long'])
25     subparser.add_argument('-d', '--deps', action='store_true',
26                            help='output dependencies along with found specs')
27 
28     subparser.add_argument('-p', '--paths', action='store_true',
29                            help='show paths to package install directories')
30     subparser.add_argument(
31         '-s', '--show', action='store', default='all',
32         choices=("packages", "installed", "activated", "all"),
33         help="show only part of output")
34     subparser.add_argument(
35         '-v', '--view', metavar='VIEW', type=str,
36         help="the view to operate on")
37 
38     subparser.add_argument(
39         'spec', nargs=argparse.REMAINDER,
40         help='spec of package to list extensions for', metavar='extendable')
41 
42 
43 def extensions(parser, args):
44     if not args.spec:
45         tty.die("extensions requires a package spec.")
46 
47     # Checks
48     spec = cmd.parse_specs(args.spec)
49     if len(spec) > 1:
50         tty.die("Can only list extensions for one package.")
51 
52     if not spec[0].package.extendable:
53         tty.die("%s is not an extendable package." % spec[0].name)
54 
55     env = ev.get_env(args, 'extensions')
56     spec = cmd.disambiguate_spec(spec[0], env)
57 
58     if not spec.package.extendable:
59         tty.die("%s does not have extensions." % spec.short_spec)
60 
61     if args.show in ("packages", "all"):
62         # List package names of extensions
63         extensions = spack.repo.path.extensions_for(spec)
64         if not extensions:
65             tty.msg("%s has no extensions." % spec.cshort_spec)
66         else:
67             tty.msg(spec.cshort_spec)
68             tty.msg("%d extensions:" % len(extensions))
69             colify(ext.name for ext in extensions)
70 
71     if args.view:
72         target = args.view
73     else:
74         target = spec.prefix
75 
76     view = YamlFilesystemView(target, spack.store.layout)
77 
78     if args.show in ("installed", "all"):
79         # List specs of installed extensions.
80         installed = [
81             s.spec for s in spack.store.db.installed_extensions_for(spec)]
82 
83         if args.show == "all":
84             print
85         if not installed:
86             tty.msg("None installed.")
87         else:
88             tty.msg("%d installed:" % len(installed))
89             cmd.display_specs(installed, args)
90 
91     if args.show in ("activated", "all"):
92         # List specs of activated extensions.
93         activated = view.extensions_layout.extension_map(spec)
94         if args.show == "all":
95             print
96         if not activated:
97             tty.msg("None activated.")
98         else:
99             tty.msg("%d activated:" % len(activated))
100             cmd.display_specs(activated.values(), args)
101
```
--- 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()

```

diff --git a/lib/spack/spack/cmd/extensions.py b/lib/spack/spack/cmd/extensions.py
--- a/lib/spack/spack/cmd/extensions.py
+++ b/lib/spack/spack/cmd/extensions.py
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
 import argparse
+import sys
 
 import llnl.util.tty as tty
 from llnl.util.tty.colify import colify
@@ -21,6 +22,8 @@
 
 
 def setup_parser(subparser):
+    subparser.epilog = 'If called without argument returns ' \
+                       'the list of all valid extendable packages'
     arguments.add_common_arguments(subparser, ['long', 'very_long'])
     subparser.add_argument('-d', '--deps', action='store_true',
                            help='output dependencies along with found specs')
@@ -42,7 +45,19 @@
 
 def extensions(parser, args):
     if not args.spec:
-        tty.die("extensions requires a package spec.")
+        # If called without arguments, list all the extendable packages
+        isatty = sys.stdout.isatty()
+        if isatty:
+            tty.info('Extendable packages:')
+
+        extendable_pkgs = []
+        for name in spack.repo.all_package_names():
+            pkg = spack.repo.get(name)
+            if pkg.extendable:
+                extendable_pkgs.append(name)
+
+        colify(extendable_pkgs, indent=4)
+        return
 
     # Checks
     spec = cmd.parse_specs(args.spec)

{"golden_diff": "diff --git a/lib/spack/spack/cmd/extensions.py b/lib/spack/spack/cmd/extensions.py\n--- a/lib/spack/spack/cmd/extensions.py\n+++ b/lib/spack/spack/cmd/extensions.py\n@@ -4,6 +4,7 @@\n # SPDX-License-Identifier: (Apache-2.0 OR MIT)\n \n import argparse\n+import sys\n \n import llnl.util.tty as tty\n from llnl.util.tty.colify import colify\n@@ -21,6 +22,8 @@\n \n \n def setup_parser(subparser):\n+    subparser.epilog = 'If called without argument returns ' \\\n+                       'the list of all valid extendable packages'\n     arguments.add_common_arguments(subparser, ['long', 'very_long'])\n     subparser.add_argument('-d', '--deps', action='store_true',\n                            help='output dependencies along with found specs')\n@@ -42,7 +45,19 @@\n \n def extensions(parser, args):\n     if not args.spec:\n-        tty.die(\"extensions requires a package spec.\")\n+        # If called without arguments, list all the extendable packages\n+        isatty = sys.stdout.isatty()\n+        if isatty:\n+            tty.info('Extendable packages:')\n+\n+        extendable_pkgs = []\n+        for name in spack.repo.all_package_names():\n+            pkg = spack.repo.get(name)\n+            if pkg.extendable:\n+                extendable_pkgs.append(name)\n+\n+        colify(extendable_pkgs, indent=4)\n+        return\n \n     # Checks\n     spec = cmd.parse_specs(args.spec)\n", "issue": "spack extensions behavior when no extendable package is specified\nIf you run `spack extensions` with no extendable package, it prints an error message telling you that a package spec is required. It would be nice if Spack also printed a list of installed extendable packages to choose from.\n\n", "before_files": [{"content": "# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other\n# Spack Project Developers. See the top-level COPYRIGHT file for details.\n#\n# SPDX-License-Identifier: (Apache-2.0 OR MIT)\n\nimport argparse\n\nimport llnl.util.tty as tty\nfrom llnl.util.tty.colify import colify\n\nimport spack.environment as ev\nimport spack.cmd as cmd\nimport spack.cmd.common.arguments as arguments\nimport spack.repo\nimport spack.store\nfrom spack.filesystem_view import YamlFilesystemView\n\ndescription = \"list extensions for package\"\nsection = \"extensions\"\nlevel = \"long\"\n\n\ndef setup_parser(subparser):\n    arguments.add_common_arguments(subparser, ['long', 'very_long'])\n    subparser.add_argument('-d', '--deps', action='store_true',\n                           help='output dependencies along with found specs')\n\n    subparser.add_argument('-p', '--paths', action='store_true',\n                           help='show paths to package install directories')\n    subparser.add_argument(\n        '-s', '--show', action='store', default='all',\n        choices=(\"packages\", \"installed\", \"activated\", \"all\"),\n        help=\"show only part of output\")\n    subparser.add_argument(\n        '-v', '--view', metavar='VIEW', type=str,\n        help=\"the view to operate on\")\n\n    subparser.add_argument(\n        'spec', nargs=argparse.REMAINDER,\n        help='spec of package to list extensions for', metavar='extendable')\n\n\ndef extensions(parser, args):\n    if not args.spec:\n        tty.die(\"extensions requires a package spec.\")\n\n    # Checks\n    spec = cmd.parse_specs(args.spec)\n    if len(spec) > 1:\n        tty.die(\"Can only list extensions for one package.\")\n\n    if not spec[0].package.extendable:\n        tty.die(\"%s is not an extendable package.\" % spec[0].name)\n\n    env = ev.get_env(args, 'extensions')\n    spec = cmd.disambiguate_spec(spec[0], env)\n\n    if not spec.package.extendable:\n        tty.die(\"%s does not have extensions.\" % spec.short_spec)\n\n    if args.show in (\"packages\", \"all\"):\n        # List package names of extensions\n        extensions = spack.repo.path.extensions_for(spec)\n        if not extensions:\n            tty.msg(\"%s has no extensions.\" % spec.cshort_spec)\n        else:\n            tty.msg(spec.cshort_spec)\n            tty.msg(\"%d extensions:\" % len(extensions))\n            colify(ext.name for ext in extensions)\n\n    if args.view:\n        target = args.view\n    else:\n        target = spec.prefix\n\n    view = YamlFilesystemView(target, spack.store.layout)\n\n    if args.show in (\"installed\", \"all\"):\n        # List specs of installed extensions.\n        installed = [\n            s.spec for s in spack.store.db.installed_extensions_for(spec)]\n\n        if args.show == \"all\":\n            print\n        if not installed:\n            tty.msg(\"None installed.\")\n        else:\n            tty.msg(\"%d installed:\" % len(installed))\n            cmd.display_specs(installed, args)\n\n    if args.show in (\"activated\", \"all\"):\n        # List specs of activated extensions.\n        activated = view.extensions_layout.extension_map(spec)\n        if args.show == \"all\":\n            print\n        if not activated:\n            tty.msg(\"None activated.\")\n        else:\n            tty.msg(\"%d activated:\" % len(activated))\n            cmd.display_specs(activated.values(), args)\n", "path": "lib/spack/spack/cmd/extensions.py"}], "after_files": [{"content": "# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other\n# Spack Project Developers. See the top-level COPYRIGHT file for details.\n#\n# SPDX-License-Identifier: (Apache-2.0 OR MIT)\n\nimport argparse\nimport sys\n\nimport llnl.util.tty as tty\nfrom llnl.util.tty.colify import colify\n\nimport spack.environment as ev\nimport spack.cmd as cmd\nimport spack.cmd.common.arguments as arguments\nimport spack.repo\nimport spack.store\nfrom spack.filesystem_view import YamlFilesystemView\n\ndescription = \"list extensions for package\"\nsection = \"extensions\"\nlevel = \"long\"\n\n\ndef setup_parser(subparser):\n    subparser.epilog = 'If called without argument returns ' \\\n                       'the list of all valid extendable packages'\n    arguments.add_common_arguments(subparser, ['long', 'very_long'])\n    subparser.add_argument('-d', '--deps', action='store_true',\n                           help='output dependencies along with found specs')\n\n    subparser.add_argument('-p', '--paths', action='store_true',\n                           help='show paths to package install directories')\n    subparser.add_argument(\n        '-s', '--show', action='store', default='all',\n        choices=(\"packages\", \"installed\", \"activated\", \"all\"),\n        help=\"show only part of output\")\n    subparser.add_argument(\n        '-v', '--view', metavar='VIEW', type=str,\n        help=\"the view to operate on\")\n\n    subparser.add_argument(\n        'spec', nargs=argparse.REMAINDER,\n        help='spec of package to list extensions for', metavar='extendable')\n\n\ndef extensions(parser, args):\n    if not args.spec:\n        # If called without arguments, list all the extendable packages\n        isatty = sys.stdout.isatty()\n        if isatty:\n            tty.info('Extendable packages:')\n\n        extendable_pkgs = []\n        for name in spack.repo.all_package_names():\n            pkg = spack.repo.get(name)\n            if pkg.extendable:\n                extendable_pkgs.append(name)\n\n        colify(extendable_pkgs, indent=4)\n        return\n\n    # Checks\n    spec = cmd.parse_specs(args.spec)\n    if len(spec) > 1:\n        tty.die(\"Can only list extensions for one package.\")\n\n    if not spec[0].package.extendable:\n        tty.die(\"%s is not an extendable package.\" % spec[0].name)\n\n    env = ev.get_env(args, 'extensions')\n    spec = cmd.disambiguate_spec(spec[0], env)\n\n    if not spec.package.extendable:\n        tty.die(\"%s does not have extensions.\" % spec.short_spec)\n\n    if args.show in (\"packages\", \"all\"):\n        # List package names of extensions\n        extensions = spack.repo.path.extensions_for(spec)\n        if not extensions:\n            tty.msg(\"%s has no extensions.\" % spec.cshort_spec)\n        else:\n            tty.msg(spec.cshort_spec)\n            tty.msg(\"%d extensions:\" % len(extensions))\n            colify(ext.name for ext in extensions)\n\n    if args.view:\n        target = args.view\n    else:\n        target = spec.prefix\n\n    view = YamlFilesystemView(target, spack.store.layout)\n\n    if args.show in (\"installed\", \"all\"):\n        # List specs of installed extensions.\n        installed = [\n            s.spec for s in spack.store.db.installed_extensions_for(spec)]\n\n        if args.show == \"all\":\n            print\n        if not installed:\n            tty.msg(\"None installed.\")\n        else:\n            tty.msg(\"%d installed:\" % len(installed))\n            cmd.display_specs(installed, args)\n\n    if args.show in (\"activated\", \"all\"):\n        # List specs of activated extensions.\n        activated = view.extensions_layout.extension_map(spec)\n        if args.show == \"all\":\n            print\n        if not activated:\n            tty.msg(\"None activated.\")\n        else:\n            tty.msg(\"%d activated:\" % len(activated))\n            cmd.display_specs(activated.values(), args)\n", "path": "lib/spack/spack/cmd/extensions.py"}]}