Skip to content
Snippets Groups Projects
Verified Commit e62ea5fc authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Support looping through pages in ls command

parent 19c4b751
No related branches found
No related tags found
1 merge request!3Ci
......@@ -267,6 +267,7 @@ def get_ls_command(group, endpoint, output_conf):
@click.option("--ordering", "-o", default=None)
@click.option("--filter", "-f", multiple=True)
@click.option("--ids", "-i", is_flag=True)
@click.option("--limit", "-l", type=click.INT, default=1)
@click.option(
"--column",
"-c",
......@@ -289,12 +290,20 @@ def get_ls_command(group, endpoint, output_conf):
format,
no_headers,
ids,
limit,
):
if ids:
no_headers = True
column = [output_conf.get("id_field", "UUID")]
format = "plain"
next_page_url = None
page_count = 0
while True:
if limit and page_count >= limit:
break
async with ctx.obj["remote"]:
if page_count == 0:
url = endpoint
params = {"page": page}
if page_size:
params["page_size"] = page_size
......@@ -307,10 +316,16 @@ def get_ls_command(group, endpoint, output_conf):
query = urllib.parse.parse_qs(f)
for k, v in query.items():
params[k] = v[0]
result = await ctx.obj["remote"].request("get", endpoint, params=params)
else:
params = {}
url = next_page_url
if not url:
break
result = await ctx.obj["remote"].request("get", url, params=params)
result.raise_for_status()
payload = await result.json()
next_page_url = payload['next']
page_count += 1
if raw:
click.echo(json.dumps(payload, sort_keys=True, indent=4))
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment