diff --git a/lib/spack/spack/cmd/config.py b/lib/spack/spack/cmd/config.py index b6055a7f6b66cd4a597d624d20803354c3b46ca2..b1a6454555ddb5264eb79b57d1366ec75495420f 100644 --- a/lib/spack/spack/cmd/config.py +++ b/lib/spack/spack/cmd/config.py @@ -56,6 +56,8 @@ def setup_parser(subparser): '--print-file', action='store_true', help="print the file name that would be edited") + sp.add_parser('list', help='list configuration sections') + def _get_scope_and_section(args): """Extract config scope and section from arguments.""" @@ -83,7 +85,6 @@ def config_get(args): With no arguments and an active environment, print the contents of the environment's manifest file (spack.yaml). - """ scope, section = _get_scope_and_section(args) @@ -113,7 +114,6 @@ def config_edit(args): With no arguments and an active environment, edit the spack.yaml for the active environment. - """ scope, section = _get_scope_and_section(args) if not scope and not section: @@ -127,8 +127,19 @@ def config_edit(args): editor(config_file) +def config_list(args): + """List the possible configuration sections. + + Used primarily for shell tab completion scripts. + """ + print(' '.join(list(spack.config.section_schemas))) + + def config(parser, args): - action = {'get': config_get, - 'blame': config_blame, - 'edit': config_edit} + action = { + 'get': config_get, + 'blame': config_blame, + 'edit': config_edit, + 'list': config_list, + } action[args.config_command](args) diff --git a/lib/spack/spack/test/cmd/config.py b/lib/spack/spack/test/cmd/config.py index 34982d46b3a20b11320375652a7b883f9ba520fb..82a9d814ea99381237e6fc4ffd7b87df3bab958b 100644 --- a/lib/spack/spack/test/cmd/config.py +++ b/lib/spack/spack/test/cmd/config.py @@ -91,3 +91,9 @@ def test_config_edit_fails_correctly_with_no_env(mutable_mock_env_path): def test_config_get_fails_correctly_with_no_env(mutable_mock_env_path): output = config('get', fail_on_error=False) assert "requires a section argument or an active environment" in output + + +def test_config_list(): + output = config('list') + assert 'compilers' in output + assert 'packages' in output diff --git a/share/spack/bash/spack-completion.in b/share/spack/bash/spack-completion.in index 2ab39a57a383837584e9cc48acfa3d7fa7ac3f72..ca15b8dfb27fca101af7f2e3fc82c32087f0aa71 100755 --- a/share/spack/bash/spack-completion.in +++ b/share/spack/bash/spack-completion.in @@ -218,7 +218,7 @@ _keys() { _config_sections() { if [[ -z "${SPACK_CONFIG_SECTIONS:-}" ]] then - SPACK_CONFIG_SECTIONS="compilers mirrors repos packages modules config upstreams" + SPACK_CONFIG_SECTIONS="$(spack config list)" fi SPACK_COMPREPLY="$SPACK_CONFIG_SECTIONS" } diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash index 9550137bff479f2d3d79bf9fe86fc9ed2bd64672..20a5d936ea0e1395cff3f125522b97aa29eff496 100755 --- a/share/spack/spack-completion.bash +++ b/share/spack/spack-completion.bash @@ -218,7 +218,7 @@ _keys() { _config_sections() { if [[ -z "${SPACK_CONFIG_SECTIONS:-}" ]] then - SPACK_CONFIG_SECTIONS="compilers mirrors repos packages modules config upstreams" + SPACK_CONFIG_SECTIONS="$(spack config list)" fi SPACK_COMPREPLY="$SPACK_CONFIG_SECTIONS" } @@ -584,7 +584,7 @@ _spack_config() { then SPACK_COMPREPLY="-h --help --scope" else - SPACK_COMPREPLY="get blame edit" + SPACK_COMPREPLY="get blame edit list" fi } @@ -615,6 +615,10 @@ _spack_config_edit() { fi } +_spack_config_list() { + SPACK_COMPREPLY="-h --help" +} + _spack_configure() { if $list_options then