rdblue commented on code in PR #5417: URL: https://github.com/apache/iceberg/pull/5417#discussion_r939720569
########## python/pyiceberg/cli/console.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import os + +import click +from rich.console import Console +from rich.table import Table +from rich.tree import Tree + +from pyiceberg.catalog.rest import RestCatalog +from pyiceberg.exceptions import NamespaceNotEmptyError, NoSuchNamespaceError, NoSuchTableError + + [email protected]() [email protected]("--catalog", type=click.Choice(["rest"], case_sensitive=False), default="rest") [email protected]("--uri", default=lambda: os.environ.get("PYICEBERG_URI")) [email protected]("--credentials", default=lambda: os.environ.get("PYICEBERG_CREDENTIALS")) [email protected]_context +def run(ctx, catalog, uri, credentials): + if catalog == "rest": + ctx.ensure_object(dict) + ctx.obj["catalog"] = RestCatalog(name="catalog", properties={}, uri=uri, credentials=credentials) + + [email protected]() [email protected]_context +def list_namespace(ctx): + # Add parent namespaces + catalog: RestCatalog = ctx.obj["catalog"] + identifiers = catalog.list_namespaces() + + table = Table(title="Namespaces") + + table.add_column("Namespace") + + for identifier in identifiers: + table.add_row(".".join(identifier)) + + console = Console() + console.print(table) + + [email protected]() [email protected]("namespace") [email protected]_context +def load_namespace(ctx, namespace: str): + catalog: RestCatalog = ctx.obj["catalog"] + console = Console() + + try: + properties = catalog.load_namespace_properties(namespace) + + if properties: + table = Table(title=f"{namespace} properties", show_header=False) Review Comment: I think we should use `Table.grid` rather than `Table` in most cases. That way, we still get nice formatting, but the output works with piping to other tools. For example: ```python poetry run pyiceberg ... list-namespace | grep le │ examples │ │ movielens │ ``` With `grid`: ```python examples movielens ``` Grid just removes the table borders, so you still get aligned text that looks nice. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
