summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-04-28 15:03:25 +0200
committerGitHub <noreply@github.com>2021-04-28 13:03:25 +0000
commit3f4c9aeca759812e09d10c17adb43ea30e4036da (patch)
tree1c41b44ec0e1e82c543740ee08cc4818f0412e28
parent9faa3221b3c11bb633af38fa750fc9ee29b73312 (diff)
downloadspack-3f4c9aeca759812e09d10c17adb43ea30e4036da.tar.gz
spack-3f4c9aeca759812e09d10c17adb43ea30e4036da.tar.bz2
spack-3f4c9aeca759812e09d10c17adb43ea30e4036da.tar.xz
spack-3f4c9aeca759812e09d10c17adb43ea30e4036da.zip
Read colorization from environment variable, if command line is not set (#23130)
-rw-r--r--lib/spack/docs/basic_usage.rst8
-rw-r--r--lib/spack/spack/main.py3
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/spack/docs/basic_usage.rst b/lib/spack/docs/basic_usage.rst
index a8a45b65cb..db69ba42e9 100644
--- a/lib/spack/docs/basic_usage.rst
+++ b/lib/spack/docs/basic_usage.rst
@@ -27,12 +27,18 @@ It is recommended that the following be put in your ``.bashrc`` file:
If you do not see colorized output when using ``less -R`` it is because color
is being disabled in the piped output. In this case, tell spack to force
-colorized output.
+colorized output with a flag
.. code-block:: console
$ spack --color always | less -R
+or an environment variable
+
+.. code-block:: console
+
+ $ SPACK_COLOR=always spack | less -R
+
--------------------------
Listing available packages
--------------------------
diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py
index be07aa3e5c..ecaf6d02f0 100644
--- a/lib/spack/spack/main.py
+++ b/lib/spack/spack/main.py
@@ -354,7 +354,8 @@ def make_argument_parser(**kwargs):
dest='help', action='store_const', const='long', default=None,
help="show help for all commands (same as spack help --all)")
parser.add_argument(
- '--color', action='store', default='auto',
+ '--color', action='store',
+ default=os.environ.get('SPACK_COLOR', 'auto'),
choices=('always', 'never', 'auto'),
help="when to colorize output (default: auto)")
parser.add_argument(