Skip to content
Snippets Groups Projects
  • Adam J. Stewart's avatar
    11f2b612
    Use `spack commands --format=bash` to generate shell completion (#14393) · 11f2b612
    Adam J. Stewart authored
    
    This PR adds a `--format=bash` option to `spack commands` to
    auto-generate the Bash programmable tab completion script. It can be
    extended to work for other shells.
    
    Progress:
    
    - [x] Fix bug in superclass initialization in `ArgparseWriter`
    - [x] Refactor `ArgparseWriter` (see below)
    - [x] Ensure that output of old `--format` options remains the same
    - [x] Add `ArgparseCompletionWriter` and `BashCompletionWriter`
    - [x] Add `--aliases` option to add command aliases
    - [x] Standardize positional argument names
    - [x] Tests for `spack commands --format=bash` coverage
    - [x] Tests to make sure `spack-completion.bash` stays up-to-date
    - [x] Tests for `spack-completion.bash` coverage
    - [x] Speed up `spack-completion.bash` by caching subroutine calls
    
    This PR also necessitates a significant refactoring of
    `ArgparseWriter`. Previously, `ArgparseWriter` was mostly a single
    `_write` method which handled everything from extracting the information
    we care about from the parser to formatting the output. Now, `_write`
    only handles recursion, while the information extraction is split into a
    separate `parse` method, and the formatting is handled by `format`. This
    allows subclasses to completely redefine how the format will appear
    without overriding all of `_write`.
    
    Co-Authored-by: default avatarTodd Gamblin <tgamblin@llnl.gov>
    11f2b612
    History
    Use `spack commands --format=bash` to generate shell completion (#14393)
    Adam J. Stewart authored
    
    This PR adds a `--format=bash` option to `spack commands` to
    auto-generate the Bash programmable tab completion script. It can be
    extended to work for other shells.
    
    Progress:
    
    - [x] Fix bug in superclass initialization in `ArgparseWriter`
    - [x] Refactor `ArgparseWriter` (see below)
    - [x] Ensure that output of old `--format` options remains the same
    - [x] Add `ArgparseCompletionWriter` and `BashCompletionWriter`
    - [x] Add `--aliases` option to add command aliases
    - [x] Standardize positional argument names
    - [x] Tests for `spack commands --format=bash` coverage
    - [x] Tests to make sure `spack-completion.bash` stays up-to-date
    - [x] Tests for `spack-completion.bash` coverage
    - [x] Speed up `spack-completion.bash` by caching subroutine calls
    
    This PR also necessitates a significant refactoring of
    `ArgparseWriter`. Previously, `ArgparseWriter` was mostly a single
    `_write` method which handled everything from extracting the information
    we care about from the parser to formatting the output. Now, `_write`
    only handles recursion, while the information extraction is split into a
    separate `parse` method, and the formatting is handled by `format`. This
    allows subclasses to completely redefine how the format will appear
    without overriding all of `_write`.
    
    Co-Authored-by: default avatarTodd Gamblin <tgamblin@llnl.gov>
.coveragerc 747 B
# -*- conf -*-
# .coveragerc to control coverage.py
[run]
parallel = True
concurrency = multiprocessing
branch = True
source = lib
omit =
     lib/spack/spack/test/*
     lib/spack/docs/*
     lib/spack/external/*
     share/spack/qa/*

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
    # Have to re-enable the standard pragma
    pragma: no cover

    # Don't complain about missing debug-only code:
    def __repr__
    if self\.debug

    # Don't complain if tests don't hit defensive assertion code:
    raise AssertionError
    raise NotImplementedError

    # Don't complain if non-runnable code isn't run:
    if 0:
    if False:
    if __name__ == .__main__.:

ignore_errors = True

[html]
directory = htmlcov