diff --git a/weaviate_cli/commands/get.py b/weaviate_cli/commands/get.py index 4bfa478..a1eb4fa 100644 --- a/weaviate_cli/commands/get.py +++ b/weaviate_cli/commands/get.py @@ -51,9 +51,13 @@ def get_collection_cli(ctx, collection): default=GetTenantsDefaults.collection, help="The name of the collection to get tenants from.", ) +@click.option( + "--tenant_id", + help="The tenant ID to get.", +) @click.option("--verbose", is_flag=True, help="Print verbose output.") @click.pass_context -def get_tenants_cli(ctx, collection, verbose): +def get_tenants_cli(ctx, collection, tenant_id, verbose): """Get tenants from a collection in Weaviate.""" client = None @@ -62,6 +66,7 @@ def get_tenants_cli(ctx, collection, verbose): tenant_manager = TenantManager(client) tenant_manager.get_tenants( collection=collection, + tenant_id=tenant_id, verbose=verbose, ) except Exception as e: diff --git a/weaviate_cli/defaults.py b/weaviate_cli/defaults.py index 8d0d49f..03a886e 100644 --- a/weaviate_cli/defaults.py +++ b/weaviate_cli/defaults.py @@ -82,6 +82,7 @@ class GetCollectionDefaults: @dataclass class GetTenantsDefaults: collection: str = "Movies" + tenant_id: Optional[str] = None verbose: bool = False diff --git a/weaviate_cli/managers/tenant_manager.py b/weaviate_cli/managers/tenant_manager.py index 4226936..108a662 100644 --- a/weaviate_cli/managers/tenant_manager.py +++ b/weaviate_cli/managers/tenant_manager.py @@ -184,6 +184,7 @@ def delete_tenants( def get_tenants( self, collection: str = GetTenantsDefaults.collection, + tenant_id: str = GetTenantsDefaults.tenant_id, verbose: bool = GetTenantsDefaults.verbose, ) -> dict: """ @@ -191,6 +192,7 @@ def get_tenants( Args: collection (str): The name of the collection to retrieve tenants from. + tenant_id (str): The ID of the tenant to retrieve. If None, retrieves all tenants. verbose (bool): If True, prints detailed tenant information. If False, prints summary. Returns: @@ -199,7 +201,14 @@ def get_tenants( Raises: Exception: If the collection does not exist or multi-tenancy is not enabled. """ - tenants = self.client.collections.get(collection).tenants.get() + if tenant_id: + tenants = self.client.collections.get(collection).tenants.get_by_names( + [tenant_id] + ) + if not tenants: + raise Exception(f"Tenant '{tenant_id}' not found in class {collection}") + else: + tenants = self.client.collections.get(collection).tenants.get() if verbose: click.echo(f"{'Tenant Name':<20}{'Activity Status':<20}")