From cd94915ce3b6bc2a6ea904eb3f655a3bf95638eb Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Fri, 20 Sep 2024 09:05:14 -0400 Subject: [PATCH 1/3] Get all pages --- cloudsmith_cli/cli/commands/list_.py | 25 ++++++++++++++++++++----- cloudsmith_cli/cli/commands/repos.py | 22 ++++++++++++++++++---- cloudsmith_cli/cli/validators.py | 2 ++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/cloudsmith_cli/cli/commands/list_.py b/cloudsmith_cli/cli/commands/list_.py index 1fa5f5af..6fb210d1 100644 --- a/cloudsmith_cli/cli/commands/list_.py +++ b/cloudsmith_cli/cli/commands/list_.py @@ -174,11 +174,26 @@ def packages(ctx, opts, owner_repo, page, page_size, query): click.echo("Getting list of packages ... ", nl=False, err=use_stderr) context_msg = "Failed to get list of packages!" - with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg): - with maybe_spinner(opts): - packages_, page_info = list_packages( - owner=owner, repo=repo, page=page, page_size=page_size, query=query - ) + if page != -1: + with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg): + with maybe_spinner(opts): + packages_, page_info = list_packages( + owner=owner, repo=repo, page=page, page_size=page_size, query=query + ) + else: + with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg): + with maybe_spinner(opts): + packages_ = [] + page_number = 1 + page_max = 999999999999 # Infinity... until we get the first page and know the real size + while page_number <= page_max: + partial_packages, page_info = list_packages( + owner=owner, repo=repo, page=page_number, page_size=page_size, query=query + ) + packages_.extend(partial_packages) + page_number += 1 + page_max = page_info.page_total + page_info = None click.secho("OK", fg="green", err=use_stderr) diff --git a/cloudsmith_cli/cli/commands/repos.py b/cloudsmith_cli/cli/commands/repos.py index db11c148..27f2fc42 100644 --- a/cloudsmith_cli/cli/commands/repos.py +++ b/cloudsmith_cli/cli/commands/repos.py @@ -117,10 +117,24 @@ def get(ctx, opts, owner_repo, page, page_size): context_msg = "Failed to get list of repositories!" with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg): - with maybe_spinner(opts): - repos_, page_info = api.list_repos( - owner=owner, repo=repo, page=page, page_size=page_size - ) + if page != -1: + with maybe_spinner(opts): + repos_, page_info = api.list_repos( + owner=owner, repo=repo, page=page, page_size=page_size + ) + else: + with maybe_spinner(opts): + repos_ = [] + page_number = 1 + page_max = 999999999999 # Infinity... until we get the first page and know the real size + while page_number <= page_max: + partial_repos, page_info = api.list_repos( + owner=owner, repo=repo, page=page_number, page_size=page_size + ) + repos_.extend(partial_repos) + page_number += 1 + page_max = page_info.page_total + page_info = None click.secho("OK", fg="green", err=use_stderr) diff --git a/cloudsmith_cli/cli/validators.py b/cloudsmith_cli/cli/validators.py index cc4016d9..a39ff65b 100644 --- a/cloudsmith_cli/cli/validators.py +++ b/cloudsmith_cli/cli/validators.py @@ -140,6 +140,8 @@ def validate_owner_repo_distro(ctx, param, value): def validate_page(ctx, param, value): """Ensure that a valid value for page is chosen.""" # pylint: disable=unused-argument + if value == -1: + return value if value == 0: raise click.BadParameter( "Page is not zero-based, please set a value to 1 or higher.", param=param From d29ab4225bd018cdcf50047c9726e56f48da1fc4 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Fri, 20 Sep 2024 09:23:38 -0400 Subject: [PATCH 2/3] run black --- cloudsmith_cli/cli/commands/list_.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cloudsmith_cli/cli/commands/list_.py b/cloudsmith_cli/cli/commands/list_.py index 6fb210d1..cfe5c792 100644 --- a/cloudsmith_cli/cli/commands/list_.py +++ b/cloudsmith_cli/cli/commands/list_.py @@ -188,7 +188,11 @@ def packages(ctx, opts, owner_repo, page, page_size, query): page_max = 999999999999 # Infinity... until we get the first page and know the real size while page_number <= page_max: partial_packages, page_info = list_packages( - owner=owner, repo=repo, page=page_number, page_size=page_size, query=query + owner=owner, + repo=repo, + page=page_number, + page_size=page_size, + query=query, ) packages_.extend(partial_packages) page_number += 1 From 2bed5e5f35738d3414fe7946a02e9f55f0d8815a Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 25 Sep 2024 10:04:58 -0400 Subject: [PATCH 3/3] add flag --- cloudsmith_cli/cli/decorators.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cloudsmith_cli/cli/decorators.py b/cloudsmith_cli/cli/decorators.py index a8b41173..a5e809b0 100644 --- a/cloudsmith_cli/cli/decorators.py +++ b/cloudsmith_cli/cli/decorators.py @@ -160,6 +160,12 @@ def common_cli_list_options(f): help="The amount of items to view per page for lists.", callback=validators.validate_page_size, ) + @click.option( + "--show-all", + default=False, + type=bool, + help="Get all pages of results, not just the first page (ls repos/pkgs only).", + ) @click.pass_context @functools.wraps(f) def wrapper(ctx, *args, **kwargs):