Read colorization from environment variable, if command line is not set (#23130)

This commit is contained in:
Harmen Stoppels 2021-04-28 15:03:25 +02:00 committed by GitHub
parent 9faa3221b3
commit 3f4c9aeca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -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 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 is being disabled in the piped output. In this case, tell spack to force
colorized output. colorized output with a flag
.. code-block:: console .. code-block:: console
$ spack --color always | less -R $ spack --color always | less -R
or an environment variable
.. code-block:: console
$ SPACK_COLOR=always spack | less -R
-------------------------- --------------------------
Listing available packages Listing available packages
-------------------------- --------------------------

View File

@ -354,7 +354,8 @@ def make_argument_parser(**kwargs):
dest='help', action='store_const', const='long', default=None, dest='help', action='store_const', const='long', default=None,
help="show help for all commands (same as spack help --all)") help="show help for all commands (same as spack help --all)")
parser.add_argument( parser.add_argument(
'--color', action='store', default='auto', '--color', action='store',
default=os.environ.get('SPACK_COLOR', 'auto'),
choices=('always', 'never', 'auto'), choices=('always', 'never', 'auto'),
help="when to colorize output (default: auto)") help="when to colorize output (default: auto)")
parser.add_argument( parser.add_argument(