Repository: spack/spack

Issue:
The 【spack cd】 does not work in the latest spack version
<!-- Explain, in a clear and concise way, the command you ran and the result you were trying to achieve.
Example: "I ran `spack find` to list all the installed packages and ..." -->

### Steps to reproduce the issue

```console
[root@centos8 ~]# spack -V
0.16.1-2002-09dcb16a70
[root@centos8 ~]# spack cd gperf
[root@centos8 ~]#
```
When I updated the spack version and installed the gperf software, then executed the **spack cd gperf** and found that nothing worked, I wondered when the bug would be fixed.


### Information on your system
[root@centos8 ~]# spack debug report
* **Spack:** 0.16.1-2002-09dcb16a70
* **Python:** 3.6.8
* **Platform:** linux-centos8-aarch64
* **Concretizer:** original
<!-- Please include the output of `spack debug report` -->

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### Additional information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [ ] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [ ] I have searched the issues of this repo and believe this is not a duplicate
- [ ] I have run the failing commands in debug mode and reported the output

<!-- We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively!

If you want to ask a question about the tool (how to use it, what it can currently do, etc.), try the `#general` channel on our Slack first. We have a welcoming community and chances are you'll get your reply faster and without opening an issue.

Other than that, thanks for taking the time to contribute to Spack! -->



Discussion:

Resolving patch:
diff --git a/lib/spack/spack/cmd/location.py b/lib/spack/spack/cmd/location.py
--- a/lib/spack/spack/cmd/location.py
+++ b/lib/spack/spack/cmd/location.py
@@ -131,12 +131,11 @@ def location(parser, args):
         print(pkg.stage.source_path)
         return
 
-    # source and build dir remain, they require the spec to be staged
+    # source dir remains, which requires the spec to be staged
     if not pkg.stage.expanded:
         tty.die("Source directory does not exist yet. "
                 "Run this to create it:",
                 "spack stage " + " ".join(args.spec))
 
-    if args.source_dir:
-        print(pkg.stage.source_path)
-        return
+    # Default to source dir.
+    print(pkg.stage.source_path)


Test patch:
diff --git a/lib/spack/spack/test/cmd/location.py b/lib/spack/spack/test/cmd/location.py
--- a/lib/spack/spack/test/cmd/location.py
+++ b/lib/spack/spack/test/cmd/location.py
@@ -53,10 +53,12 @@ def test_location_build_dir(mock_spec):
     assert location('--build-dir', spec.name).strip() == pkg.stage.source_path
 
 
+@pytest.mark.regression('22738')
 def test_location_source_dir(mock_spec):
     """Tests spack location --source-dir."""
     spec, pkg = mock_spec
     assert location('--source-dir', spec.name).strip() == pkg.stage.source_path
+    assert location(spec.name).strip() == pkg.stage.source_path
 
 
 def test_location_source_dir_missing():