|
1 | 1 | import collections |
2 | 2 | import platform |
3 | 3 | from enum import Enum |
4 | | -from typing import Any, Dict, List |
| 4 | +from typing import Any, Dict, List, Optional |
5 | 5 |
|
6 | 6 | import click |
7 | 7 |
|
@@ -33,6 +33,26 @@ def list_commands(self, ctx): |
33 | 33 | return self.commands |
34 | 34 |
|
35 | 35 |
|
| 36 | +def paginated(command): |
| 37 | + command = click.option( |
| 38 | + "-o", |
| 39 | + "--offset", |
| 40 | + type=int, |
| 41 | + default=None, |
| 42 | + is_flag=False, |
| 43 | + help="Offsets the given number of records in the paginated JSON response.", |
| 44 | + )(command) |
| 45 | + command = click.option( |
| 46 | + "-l", |
| 47 | + "--limit", |
| 48 | + type=int, |
| 49 | + default=None, |
| 50 | + is_flag=False, |
| 51 | + help="Limits the number of records to return in the paginated JSON response.", |
| 52 | + )(command) |
| 53 | + return command |
| 54 | + |
| 55 | + |
36 | 56 | @click.group(cls=OrderedGroup) |
37 | 57 | @click.option( |
38 | 58 | "-U", |
@@ -149,35 +169,23 @@ def logout(ctx): |
149 | 169 |
|
150 | 170 |
|
151 | 171 | @cli.command() |
152 | | -@click.option( |
153 | | - "-o", |
154 | | - "--offset", |
155 | | - type=int, |
156 | | - default=None, |
157 | | - is_flag=False, |
158 | | - help="Offsets the given number of projects in the paginated JSON response", |
159 | | -) |
160 | | -@click.option( |
161 | | - "-l", |
162 | | - "--limit", |
163 | | - type=int, |
164 | | - default=None, |
165 | | - is_flag=False, |
166 | | - help="Limits the number of projects to return in the paginated JSON response", |
167 | | -) |
| 172 | +@paginated |
168 | 173 | @click.option( |
169 | 174 | "--include-public/--no-public", |
170 | 175 | default=False, |
171 | 176 | is_flag=True, |
172 | 177 | help="Includes the public project in the list. Default: False", |
173 | 178 | ) |
174 | 179 | @click.pass_context |
175 | | -def list_projects(ctx, **opts): |
| 180 | +def list_projects(ctx, include_public, **opts): |
176 | 181 | """List QFieldCloud projects.""" |
177 | 182 |
|
178 | 183 | log("Listing projects…") |
179 | 184 |
|
180 | | - projects: List[Dict[str, Any]] = ctx.obj["client"].list_projects(**opts) |
| 185 | + projects: List[Dict[str, Any]] = ctx.obj["client"].list_projects( |
| 186 | + include_public, |
| 187 | + sdk.Pagination(**opts), |
| 188 | + ) |
181 | 189 |
|
182 | 190 | if ctx.obj["format_json"]: |
183 | 191 | print_json(projects) |
@@ -381,29 +389,18 @@ def delete_files(ctx, project_id, paths, throw_on_error): |
381 | 389 | type=sdk.JobTypes, |
382 | 390 | help="Job type. One of package, delta_apply or process_projectfile.", |
383 | 391 | ) |
384 | | -@click.option( |
385 | | - "-o", |
386 | | - "--offset", |
387 | | - type=int, |
388 | | - default=None, |
389 | | - is_flag=False, |
390 | | - help="Offsets the given number of projects in the paginated JSON response", |
391 | | -) |
392 | | -@click.option( |
393 | | - "-l", |
394 | | - "--limit", |
395 | | - type=int, |
396 | | - default=None, |
397 | | - is_flag=False, |
398 | | - help="Limits the number of projects to return in the paginated JSON response", |
399 | | -) |
| 392 | +@paginated |
400 | 393 | @click.pass_context |
401 | | -def list_jobs(ctx, project_id, **opts): |
| 394 | +def list_jobs(ctx, project_id, job_type: Optional[sdk.JobTypes], **opts): |
402 | 395 | """List project jobs.""" |
403 | 396 |
|
404 | 397 | log(f'Listing project "{project_id}" jobs…') |
405 | 398 |
|
406 | | - jobs: List[Dict[Any]] = ctx.obj["client"].list_jobs(project_id, **opts) |
| 399 | + jobs: List[Dict[Any]] = ctx.obj["client"].list_jobs( |
| 400 | + project_id, |
| 401 | + job_type, |
| 402 | + sdk.Pagination(**opts), |
| 403 | + ) |
407 | 404 |
|
408 | 405 | if ctx.obj["format_json"]: |
409 | 406 | print_json(jobs) |
|
0 commit comments