Check if the shell is asking for tab completion, process that, then exit early. Called from :meth:`main` before the program is invoked. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds
(
self,
ctx_args: cabc.MutableMapping[str, t.Any],
prog_name: str,
complete_var: str | None = None,
)
| 1533 | sys.exit(1) |
| 1534 | |
| 1535 | def _main_shell_completion( |
| 1536 | self, |
| 1537 | ctx_args: cabc.MutableMapping[str, t.Any], |
| 1538 | prog_name: str, |
| 1539 | complete_var: str | None = None, |
| 1540 | ) -> None: |
| 1541 | """Check if the shell is asking for tab completion, process |
| 1542 | that, then exit early. Called from :meth:`main` before the |
| 1543 | program is invoked. |
| 1544 | |
| 1545 | :param prog_name: Name of the executable in the shell. |
| 1546 | :param complete_var: Name of the environment variable that holds |
| 1547 | the completion instruction. Defaults to |
| 1548 | ``_{PROG_NAME}_COMPLETE``. |
| 1549 | |
| 1550 | .. versionchanged:: 8.2.0 |
| 1551 | Dots (``.``) in ``prog_name`` are replaced with underscores (``_``). |
| 1552 | """ |
| 1553 | if complete_var is None: |
| 1554 | complete_name = prog_name.replace("-", "_").replace(".", "_") |
| 1555 | complete_var = f"_{complete_name}_COMPLETE".upper() |
| 1556 | |
| 1557 | instruction = os.environ.get(complete_var) |
| 1558 | |
| 1559 | if not instruction: |
| 1560 | return |
| 1561 | |
| 1562 | from .shell_completion import shell_complete |
| 1563 | |
| 1564 | rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction) |
| 1565 | sys.exit(rv) |
| 1566 | |
| 1567 | def __call__(self, *args: t.Any, **kwargs: t.Any) -> t.Any: |
| 1568 | """Alias for :meth:`main`.""" |
no test coverage detected