Skip to content

Commit

Permalink
factorize print table
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvaingaudan committed Sep 27, 2024
1 parent 51c1a41 commit 903062b
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions arlas/cli/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def configuration(config: str = typer.Option(help="Name of the ARLAS configurati
def list_collections():
config = variables["arlas"]
collections = Service.list_collections(config)
tab = PrettyTable(collections[0], sortby="name", align="l")
tab.add_rows(collections[1:])
print(tab)
__print_table(collections[0], collections[1:], sortby="name")


@collections.command(help="Count the number of hits within a collection (or all collection if not provided)")
Expand All @@ -31,9 +29,7 @@ def count(
):
config = variables["arlas"]
count = Service.count_collection(config, collection)
tab = PrettyTable(count[0], sortby="collection name", align="l")
tab.add_rows(count[1:])
print(tab)
__print_table(count[0], count[1:], sortby="collection name")


@collections.command(help="Describe a collection")
Expand All @@ -42,14 +38,10 @@ def describe(
):
config = variables["arlas"]
fields = Service.describe_collection(config, collection)
tab = PrettyTable(fields[0], sortby="field name", align="l")
tab.add_rows(fields[1:])
print(tab)
__print_table(fields[0], fields[1:], sortby="field name")

fields = Service.metadata_collection(config, collection)
tab = PrettyTable(fields[0], align="l")
tab.add_rows(fields[1:])
print(tab)
__print_table(fields[0], fields[1:], sortby=None)


@collections.command(help="Set collection visibility to public")
Expand Down Expand Up @@ -108,9 +100,7 @@ def set_field_display_name(
):
config = variables["arlas"]
fields = Service.set_collection_field_display_name(config, collection, field_path, display_name)
tab = PrettyTable(fields[0], align="l")
tab.add_rows(fields[1:])
print(tab)
__print_table(fields[0], fields[1:], sortby=None)


@collections.command(help="Display a sample of a collection")
Expand Down Expand Up @@ -179,3 +169,10 @@ def create(
geometry_path=geometry_path,
date_path=date_path)
print("Collection {} created on {}".format(collection, config))


def __print_table(field_names: list[str], rows, sortby: str = None):
tab = PrettyTable(field_names, sortby=sortby, align="l")
tab.add_rows(rows)
print(tab)

0 comments on commit 903062b

Please sign in to comment.