Skip to content

Commit a8e8570

Browse files
feat: rename --show-all to --page-all and support it in page-size (#238)
* feat: rename `--show-all` to `--page-all` and support it in page-size * Bump version: 1.9.4 → 1.9.5 * add show-all test to license * add changelog and revert version, will be included in bundled release * Update deny code to reflect page-all * change entitlement from show-all to page-all
1 parent f189b3e commit a8e8570

File tree

19 files changed

+135
-87
lines changed

19 files changed

+135
-87
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111

12+
- Set `--show-all` to alias `--page-all`
13+
- Add the ability to use a shortcut within `--page-size` to use pass `-1` or `*` to retrieve all pages i.e. `--page-size -1` or `--page-size *` (note the wildcard may require escaping in some shell environments)
1214
- Added support for deny policy management commands (list, create, get, update, delete)
1315

1416
### Fixed

cloudsmith_cli/cli/commands/entitlements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def wrapper(ctx, *args, **kwargs):
7373
return wrapper
7474

7575

76-
def list_entitlements(ctx, opts, owner_repo, page, page_size, show_tokens, show_all):
76+
def list_entitlements(ctx, opts, owner_repo, page, page_size, show_tokens, page_all):
7777
"""
7878
List entitlements for a repository.
7979
@@ -103,7 +103,7 @@ def list_entitlements(ctx, opts, owner_repo, page, page_size, show_tokens, show_
103103
with maybe_spinner(opts):
104104
entitlements_, page_info = paginate_results(
105105
api.list_entitlements,
106-
show_all=show_all,
106+
page_all=page_all,
107107
page=page,
108108
page_size=page_size,
109109
owner=owner,

cloudsmith_cli/cli/commands/list_.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def entitlements_(*args, **kwargs): # pylint: disable=missing-docstring
157157
help=("Sort packages by field. Prefix with '-' for descending order."),
158158
)
159159
@click.pass_context
160-
def packages(ctx, opts, owner_repo, page, page_size, query, sort, show_all):
160+
def packages(ctx, opts, owner_repo, page, page_size, query, sort, page_all):
161161
"""
162162
List packages for a repository.
163163
@@ -220,7 +220,7 @@ def packages(ctx, opts, owner_repo, page, page_size, query, sort, show_all):
220220
with maybe_spinner(opts):
221221
packages_, page_info = paginate_results(
222222
list_packages,
223-
show_all=show_all,
223+
page_all=page_all,
224224
page=page,
225225
page_size=page_size,
226226
owner=owner,
@@ -262,9 +262,9 @@ def packages(ctx, opts, owner_repo, page, page_size, query, sort, show_all):
262262
list_suffix = "package%s" % ("s" if num_results != 1 else "")
263263
utils.pretty_print_list_info(
264264
num_results=num_results,
265-
page_info=None if show_all else page_info,
266-
suffix=f"{list_suffix} retrieved" if show_all else f"{list_suffix} visible",
267-
show_all=show_all,
265+
page_info=None if page_all else page_info,
266+
suffix=f"{list_suffix} retrieved" if page_all else f"{list_suffix} visible",
267+
page_all=page_all,
268268
)
269269

270270

@@ -282,7 +282,7 @@ def packages(ctx, opts, owner_repo, page, page_size, query, sort, show_all):
282282
required=False,
283283
)
284284
@click.pass_context
285-
def repos(ctx, opts, owner_repo, page, page_size, show_all):
285+
def repos(ctx, opts, owner_repo, page, page_size, page_all):
286286
"""
287287
List repositories for a namespace (owner).
288288

cloudsmith_cli/cli/commands/metrics/entitlements.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def usage(ctx, opts, owner_repo, tokens, start, finish):
124124
repo = None
125125

126126
context_msg = "Failed to get list of metrics!"
127+
data = {}
127128
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
128129
with maybe_spinner(opts):
129130
if owner and repo:

cloudsmith_cli/cli/commands/policy/deny.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def deny_policy(*args, **kwargs):
6161
@decorators.initialise_api
6262
@click.argument("owner")
6363
@click.pass_context
64-
def list_deny_policies(ctx, opts, owner, page, page_size, show_all):
64+
def list_deny_policies(ctx, opts, owner, page, page_size, page_all):
6565
"""List deny policies for an organization."""
6666
use_stderr = opts.output != "pretty"
6767
click.echo("Getting deny policies ... ", nl=False, err=use_stderr)
@@ -70,7 +70,7 @@ def list_deny_policies(ctx, opts, owner, page, page_size, show_all):
7070
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
7171
with maybe_spinner(opts):
7272
data, page_info = paginate_results(
73-
orgs.list_deny_policies, show_all, page, page_size, owner=owner
73+
orgs.list_deny_policies, page_all, page, page_size, owner=owner
7474
)
7575

7676
click.secho("OK", fg="green", err=use_stderr)
@@ -86,9 +86,9 @@ def list_deny_policies(ctx, opts, owner, page, page_size, show_all):
8686
list_suffix = "deny polic%s" % ("y" if num_results == 1 else "ies")
8787
utils.pretty_print_list_info(
8888
num_results=num_results,
89-
page_info=None if show_all else page_info,
89+
page_info=None if page_all else page_info,
9090
suffix=list_suffix,
91-
show_all=show_all,
91+
page_all=page_all,
9292
)
9393

9494

cloudsmith_cli/cli/commands/policy/license.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def licence(*args, **kwargs):
8282
"owner", metavar="OWNER", callback=validators.validate_owner, required=True
8383
)
8484
@click.pass_context
85-
def ls(ctx, opts, owner, page, page_size, show_all):
85+
def ls(ctx, opts, owner, page, page_size, page_all):
8686
"""
8787
List license policies.
8888
@@ -108,7 +108,7 @@ def ls(ctx, opts, owner, page, page_size, show_all):
108108
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
109109
with maybe_spinner(opts):
110110
policies, page_info = paginate_results(
111-
api.list_license_policies, show_all, page, page_size, owner=owner
111+
api.list_license_policies, page_all, page, page_size, owner=owner
112112
)
113113

114114
click.secho("OK", fg="green", err=use_stderr)
@@ -124,9 +124,9 @@ def ls(ctx, opts, owner, page, page_size, show_all):
124124
list_suffix = "license polic%s" % ("y" if num_results == 1 else "ies")
125125
utils.pretty_print_list_info(
126126
num_results=num_results,
127-
page_info=None if show_all else page_info,
127+
page_info=None if page_all else page_info,
128128
suffix=list_suffix,
129-
show_all=show_all,
129+
page_all=page_all,
130130
)
131131

132132

cloudsmith_cli/cli/commands/policy/vulnerability.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def vulnerability(*args, **kwargs):
7272
"owner", metavar="OWNER", callback=validators.validate_owner, required=True
7373
)
7474
@click.pass_context
75-
def ls(ctx, opts, owner, page, page_size, show_all):
75+
def ls(ctx, opts, owner, page, page_size, page_all):
7676
"""
7777
List vulnerability policies.
7878
@@ -98,7 +98,7 @@ def ls(ctx, opts, owner, page, page_size, show_all):
9898
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
9999
with maybe_spinner(opts):
100100
policies, page_info = paginate_results(
101-
api.list_vulnerability_policies, show_all, page, page_size, owner=owner
101+
api.list_vulnerability_policies, page_all, page, page_size, owner=owner
102102
)
103103

104104
click.secho("OK", fg="green", err=use_stderr)
@@ -114,9 +114,9 @@ def ls(ctx, opts, owner, page, page_size, show_all):
114114
list_suffix = "vulnerability polic%s" % ("y" if num_results == 1 else "ies")
115115
utils.pretty_print_list_info(
116116
num_results=num_results,
117-
page_info=None if show_all else page_info,
117+
page_info=None if page_all else page_info,
118118
suffix=list_suffix,
119-
show_all=show_all,
119+
page_all=page_all,
120120
)
121121

122122

cloudsmith_cli/cli/commands/repos.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .main import main
1414

1515

16-
def print_repositories(opts, data, page_info=None, show_list_info=True, show_all=False):
16+
def print_repositories(opts, data, page_info=None, show_list_info=True, page_all=False):
1717
"""Print repositories as a table or output in another format."""
1818
headers = [
1919
"Name",
@@ -56,9 +56,9 @@ def print_repositories(opts, data, page_info=None, show_list_info=True, show_all
5656
list_suffix = "repositor%s" % ("ies" if num_results != 1 else "y")
5757
utils.pretty_print_list_info(
5858
num_results=num_results,
59-
page_info=None if show_all else page_info,
60-
suffix=f"{list_suffix} retrieved" if show_all else f"{list_suffix} visible",
61-
show_all=show_all,
59+
page_info=None if page_all else page_info,
60+
suffix=f"{list_suffix} retrieved" if page_all else f"{list_suffix} visible",
61+
page_all=page_all,
6262
)
6363

6464

@@ -90,7 +90,7 @@ def repositories(ctx, opts): # pylink: disable=unused-argument
9090
required=False,
9191
)
9292
@click.pass_context
93-
def get(ctx, opts, owner_repo, page, page_size, show_all):
93+
def get(ctx, opts, owner_repo, page, page_size, page_all):
9494
"""
9595
List repositories for a namespace (owner).
9696
@@ -119,9 +119,9 @@ def get(ctx, opts, owner_repo, page, page_size, show_all):
119119
owner = None
120120
repo = None
121121

122-
if show_all and repo:
122+
if page_all and repo:
123123
raise click.UsageError(
124-
"The --show-all option cannot be used when specifying a single repository (OWNER/REPO). Omit the repository slug or remove --show-all."
124+
"The --page-all option cannot be used when specifying a single repository (OWNER/REPO). Omit the repository slug or remove --page-all."
125125
)
126126

127127
click.echo("Getting list of repositories ... ", nl=False, err=use_stderr)
@@ -130,7 +130,7 @@ def get(ctx, opts, owner_repo, page, page_size, show_all):
130130
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):
131131
with maybe_spinner(opts):
132132
repos_, page_info = paginate_results(
133-
api.list_repos, show_all, page, page_size, owner=owner, repo=repo
133+
api.list_repos, page_all, page, page_size, owner=owner, repo=repo
134134
)
135135

136136
click.secho("OK", fg="green", err=use_stderr)
@@ -143,7 +143,7 @@ def get(ctx, opts, owner_repo, page, page_size, show_all):
143143
data=repos_,
144144
show_list_info=True,
145145
page_info=page_info,
146-
show_all=show_all,
146+
page_all=page_all,
147147
)
148148

149149

cloudsmith_cli/cli/commands/upstream.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
]
3939

4040

41-
def print_upstreams(upstreams, upstream_fmt, page_info=None, show_all=False):
41+
def print_upstreams(upstreams, upstream_fmt, page_info=None, page_all=False):
4242
"""Print upstreams as a table or output in another format."""
4343

4444
def build_row(u):
@@ -120,9 +120,9 @@ def build_row(u):
120120
list_suffix = "upstream%s" % ("" if num_results == 1 else "s")
121121
utils.pretty_print_list_info(
122122
num_results=num_results,
123-
page_info=None if show_all else page_info,
123+
page_info=None if page_all else page_info,
124124
suffix=list_suffix,
125-
show_all=show_all,
125+
page_all=page_all,
126126
)
127127

128128

@@ -170,7 +170,7 @@ def build_upstream_list_command(upstream_fmt):
170170
"owner_repo", metavar="OWNER/REPO", callback=validators.validate_owner_repo
171171
)
172172
@click.pass_context
173-
def func(ctx, opts, owner_repo, page, page_size, show_all):
173+
def func(ctx, opts, owner_repo, page, page_size, page_all):
174174
owner, repo = owner_repo
175175

176176
# Use stderr for messages if the output is something else (e.g. # JSON)
@@ -184,7 +184,7 @@ def func(ctx, opts, owner_repo, page, page_size, show_all):
184184
with maybe_spinner(opts):
185185
upstreams, page_info = paginate_results(
186186
api.list_upstreams,
187-
show_all,
187+
page_all,
188188
page,
189189
page_size,
190190
owner=owner,
@@ -198,7 +198,7 @@ def func(ctx, opts, owner_repo, page, page_size, show_all):
198198
if utils.maybe_print_as_json(opts, upstreams, page_info):
199199
return
200200

201-
print_upstreams(upstreams, upstream_fmt, page_info, show_all)
201+
print_upstreams(upstreams, upstream_fmt, page_info, page_all)
202202

203203
func.__doc__ = f"""
204204
List {upstream_fmt} upstreams for a repository.

cloudsmith_cli/cli/decorators.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def common_cli_list_options(f):
150150
"-l",
151151
"--page-size",
152152
default=30,
153-
type=int,
154-
help="The amount of items to view per page for lists.",
153+
type=validators.IntOrWildcard(),
154+
help="The amount of items to view per page for lists. Use '*' to show all results.",
155155
callback=validators.validate_page_size,
156156
)
157157
@click.option(
@@ -163,6 +163,7 @@ def common_cli_list_options(f):
163163
callback=validators.validate_page,
164164
)
165165
@click.option(
166+
"--page-all",
166167
"--show-all",
167168
default=False,
168169
is_flag=True,
@@ -173,10 +174,18 @@ def common_cli_list_options(f):
173174
def wrapper(ctx, *args, **kwargs):
174175
# pylint: disable=missing-docstring
175176
opts = config.get_or_create_options(ctx)
177+
178+
# Handle wildcard page_size (converts to page_all behavior)
179+
page_size = kwargs.get("page_size")
180+
if page_size == -1:
181+
kwargs["page_all"] = True
182+
# Validate that wildcard isn't used with explicit --page
183+
validators.enforce_page_all_exclusive(ctx, wildcard_used=True)
184+
176185
# Order-independent validation: perform after all options parsed.
177-
show_all = kwargs.get("show_all")
178-
if show_all:
179-
validators.enforce_show_all_exclusive(ctx)
186+
page_all = kwargs.get("page_all")
187+
if page_all:
188+
validators.enforce_page_all_exclusive(ctx)
180189
kwargs["opts"] = opts
181190
return ctx.invoke(f, *args, **kwargs)
182191

0 commit comments

Comments
 (0)