-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
124 additions
and
7 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
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
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,16 @@ | ||
# CLI Reference | ||
|
||
python-re3data. | ||
|
||
**Usage**: | ||
|
||
```console | ||
$ re3data [OPTIONS] COMMAND [ARGS]... | ||
``` | ||
|
||
**Options**: | ||
|
||
* `-V, --version`: Show python-re3data version and exit. | ||
* `--install-completion`: Install completion for the current shell. | ||
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation. | ||
* `--help`: Show this message and exit. |
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
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,41 @@ | ||
"""re3data command line interface.""" | ||
|
||
import logging | ||
import sys | ||
import typing | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
import typer | ||
except ImportError: | ||
logger.error("`typer` is missing. Please run 'pip install python-re3data[cli]' to use the CLI.") | ||
sys.exit(1) | ||
|
||
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]} | ||
|
||
app = typer.Typer(no_args_is_help=True, context_settings=CONTEXT_SETTINGS) | ||
|
||
|
||
def _version_callback(show_version: bool) -> None: | ||
# Ref: https://typer.tiangolo.com/tutorial/options/version/ | ||
from re3data import __version__ | ||
|
||
if show_version: | ||
typer.echo(f"{__version__}") | ||
raise typer.Exit | ||
|
||
|
||
@app.callback(context_settings=CONTEXT_SETTINGS) | ||
def callback( | ||
version: typing.Annotated[ | ||
bool, | ||
typer.Option( | ||
"--version", | ||
"-V", | ||
help="Show python-re3data version and exit.", | ||
callback=_version_callback, | ||
), | ||
] = False, | ||
) -> None: | ||
"""python-re3data.""" |
Empty file.
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,52 @@ | ||
# SPDX-FileCopyrightText: 2024 Heinz-Alexander Fütterer | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import sys | ||
from importlib import reload | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from typer.testing import CliRunner | ||
|
||
from re3data import __version__ | ||
from re3data._cli import app | ||
|
||
runner = CliRunner() | ||
|
||
HELP_OPTION_NAMES = ("-h", "--help") | ||
VERSION_OPTION_NAMES = ("-V", "--version") | ||
|
||
|
||
def test_no_args_displays_help() -> None: | ||
result = runner.invoke(app) | ||
assert result.exit_code == 0 | ||
assert "Usage" in result.output | ||
assert "Options" in result.output | ||
assert "Show this message and exit" in result.output | ||
|
||
|
||
@pytest.mark.parametrize("help_option_name", HELP_OPTION_NAMES) | ||
def test_help_option_displays_help(help_option_name: str) -> None: | ||
result = runner.invoke(app, [help_option_name]) | ||
assert result.exit_code == 0 | ||
assert "Usage" in result.output | ||
assert "Options" in result.output | ||
assert "Show this message and exit" in result.output | ||
|
||
|
||
@pytest.mark.parametrize("version_option_name", VERSION_OPTION_NAMES) | ||
def test_version_option_displays_version(version_option_name: str) -> None: | ||
result = runner.invoke(app, [version_option_name]) | ||
assert result.exit_code == 0 | ||
assert __version__ in result.output | ||
|
||
|
||
def test_typer_missing_message(caplog: pytest.LogCaptureFixture) -> None: | ||
# act as if "typer" is not installed | ||
with patch.dict(sys.modules, {"typer": None}): | ||
with pytest.raises(SystemExit) as exc_info: | ||
reload(sys.modules["re3data._cli"]) | ||
assert exc_info.type == SystemExit | ||
assert exc_info.value.code == 1 | ||
assert "Please run 'pip install python-re3data[cli]'" in caplog.text |