-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1076 from evelikov/shell-completion
Add shell completion support
- Loading branch information
Showing
9 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,3 +142,4 @@ Contributors | |
- Сергій <[email protected]> | ||
- Mersho <[email protected]> | ||
- Skyler Grey <[email protected]> | ||
- Emil Velikov <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,16 @@ repos: | |
- id: reuse-lint-file | ||
``` | ||
|
||
### Shell completion | ||
|
||
You can generate a shell completion script with `reuse --print-completion bash`. | ||
Replace 'bash' as needed. You must place the printed text in a file dictated by | ||
your shell to benefit from completions. | ||
|
||
This functionality depends on `shtab`, which is an optional dependency. To | ||
benefit from this feature, install reuse with the `completion` extra, like | ||
`pipx install reuse[completion]`. | ||
|
||
## Maintainers | ||
|
||
- Carmen Bianca Bakker <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Added `--print-completion` using a new `shtab` optional dependency. (#1076) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.. | ||
SPDX-FileCopyrightText: 2019 Free Software Foundation Europe e.V. <https://fsfe.org> | ||
SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> | ||
SPDX-FileCopyrightText: 2024 Emil Velikov <[email protected]> | ||
SPDX-License-Identifier: CC-BY-SA-4.0 | ||
|
||
|
@@ -77,6 +78,17 @@ Options | |
current working directory's VCS repository, or to the current working | ||
directory. | ||
|
||
.. option:: -s, --print-completion SHELL | ||
|
||
Print a static shell completion script for the given shell and exit. You must | ||
place the printed text in a file dictated by your shell before the completions | ||
will function. For Bash, this file is | ||
``${XDG_DATA_HOME}/bash-completion/reuse``. | ||
|
||
This option depends on ``shtab``, which is an optional dependency of | ||
:program:`reuse`. The supported shells depend on your installed version of | ||
``shtab``. | ||
|
||
.. option:: -h, --help | ||
|
||
Display help and exit. If no command is provided, this option is implied. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,21 @@ | |
# SPDX-FileCopyrightText: 2024 Carmen Bianca BAKKER <[email protected]> | ||
# SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com> | ||
# SPDX-FileCopyrightText: 2024 Kerry McAdams <github@klmcadams> | ||
# SPDX-FileCopyrightText: 2024 Emil Velikov <[email protected]> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
"""Entry functions for reuse.""" | ||
|
||
import argparse | ||
import contextlib | ||
import logging | ||
import os | ||
import sys | ||
import warnings | ||
from gettext import gettext as _ | ||
from pathlib import Path | ||
from types import ModuleType | ||
from typing import IO, Callable, Optional, Type, cast | ||
|
||
from . import ( | ||
|
@@ -34,6 +37,10 @@ | |
from .project import GlobalLicensingConflict, Project | ||
from .vcs import find_root | ||
|
||
shtab: Optional[ModuleType] = None | ||
with contextlib.suppress(ImportError): | ||
import shtab # type: ignore[no-redef,import-not-found] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
_DESCRIPTION_LINES = [ | ||
|
@@ -103,6 +110,9 @@ def parser() -> argparse.ArgumentParser: | |
type=PathType("r", force_directory=True), | ||
help=_("define root of project"), | ||
) | ||
if shtab: | ||
# This is magic. Running `reuse -s bash` now prints bash completions. | ||
shtab.add_argument_to(parser, ["-s", "--print-completion"]) | ||
parser.add_argument( | ||
"--version", | ||
action="store_true", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters