(shell: str, names: List[str])
| 104 | |
| 105 | |
| 106 | def print_completion_script(shell: str, names: List[str]) -> None: |
| 107 | # Grab all .completion files in invoke/completion/. (These used to have no |
| 108 | # suffix, but surprise, that's super fragile. |
| 109 | completions = { |
| 110 | os.path.splitext(os.path.basename(x))[0]: x |
| 111 | for x in glob.glob( |
| 112 | os.path.join( |
| 113 | os.path.dirname(os.path.realpath(__file__)), "*.completion" |
| 114 | ) |
| 115 | ) |
| 116 | } |
| 117 | try: |
| 118 | path = completions[shell] |
| 119 | except KeyError: |
| 120 | err = 'Completion for shell "{}" not supported (options are: {}).' |
| 121 | raise ParseError(err.format(shell, ", ".join(sorted(completions)))) |
| 122 | debug("Printing completion script from {}".format(path)) |
| 123 | # Choose one arbitrary program name for script's own internal invocation |
| 124 | # (also used to construct completion function names when necessary) |
| 125 | binary = names[0] |
| 126 | with open(path, "r") as script: |
| 127 | print( |
| 128 | script.read().format(binary=binary, spaced_names=" ".join(names)) |
| 129 | ) |
no test coverage detected
searching dependent graphs…