Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mkdocs/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ hide:

Pyiceberg comes with a CLI that's available after installing the `pyiceberg` package.

You can pass the path to the Catalog using the `--uri` and `--credential` argument, but it is recommended to setup a `~/.pyiceberg.yaml` config as described in the [Catalog](configuration.md) section.
You can pass the path to the Catalog using `--uri` and `--credential`. For REST catalogs that require a path prefix, you can also set `--prefix`. It is still recommended to set up a `~/.pyiceberg.yaml` config as described in the [Catalog](configuration.md) section.

```sh
➜ pyiceberg --help
Expand All @@ -39,6 +39,7 @@ Options:
--ugi TEXT
--uri TEXT
--credential TEXT
--prefix TEXT
--help Show this message and exit.

Commands:
Expand Down
4 changes: 4 additions & 0 deletions pyiceberg/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def wrapper(*args: Any, **kwargs: Any): # type: ignore
@click.option("--ugi")
@click.option("--uri")
@click.option("--credential")
@click.option("--prefix")
@click.pass_context
def run(
ctx: Context,
Expand All @@ -76,6 +77,7 @@ def run(
ugi: str | None,
uri: str | None,
credential: str | None,
prefix: str | None,
) -> None:
logging.basicConfig(
level=getattr(logging, log_level.upper()),
Expand All @@ -89,6 +91,8 @@ def run(
properties[URI] = uri
if credential:
properties["credential"] = credential
if prefix:
properties["prefix"] = prefix

ctx.ensure_object(dict)
if output == "text":
Expand Down
15 changes: 15 additions & 0 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,18 @@ def test_log_level_cli_overrides_env(mocker: MockFixture) -> None:
mock_basicConfig.assert_called_once()
call_kwargs = mock_basicConfig.call_args[1]
assert call_kwargs["level"] == logging.ERROR


def test_prefix_cli_option_forwarded_to_catalog(mocker: MockFixture) -> None:
mock_basicConfig = mocker.patch("logging.basicConfig")
mock_catalog = MagicMock(spec=InMemoryCatalog)
mock_catalog.list_tables.return_value = []
mock_catalog.list_namespaces.return_value = []
mock_load_catalog = mocker.patch("pyiceberg.cli.console.load_catalog", return_value=mock_catalog)

runner = CliRunner()
result = runner.invoke(run, ["--catalog", "rest", "--uri", "https://example.invalid", "--prefix", "v1/ws", "list"])

assert result.exit_code == 0
mock_basicConfig.assert_called_once()
mock_load_catalog.assert_called_once_with("rest", uri="https://example.invalid", prefix="v1/ws")
Loading