Skip to content

Commit a835310

Browse files
committed
tools: cloud: apps: user-selectable organisation list
If an organisation is not explicitly provided to `cloud apps list`, pull the list of valid orgs and display them to the user to select one. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 42ac1d5 commit a835310

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/infuse_iot/tools/cloud.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def add_parser(cls, parser):
403403
tool_parser = parser_coap.add_subparsers(title="commands", metavar="<command>", required=True)
404404

405405
list_parser = tool_parser.add_parser("list", help="List all application releases")
406-
list_parser.add_argument("--org", "-o", type=str, required=True, help="Organisation ID")
406+
list_parser.add_argument("--org", "-o", type=str, help="Organisation ID")
407407
list_parser.set_defaults(command_fn=cls.list)
408408

409409
info_parser = tool_parser.add_parser("info", help="Display summary of application releases")
@@ -424,7 +424,20 @@ def run(self):
424424
self.args.command_fn(self, client)
425425

426426
def list(self, client: Client):
427-
applications = get_applications_by_organisation_id.sync(client=client, id=UUID(self.args.org))
427+
org: UUID
428+
if self.args.org is None:
429+
orgs = get_all_organisations.sync(client=client)
430+
if isinstance(orgs, models.Error) or orgs is None:
431+
sys.exit(f"Organisation query failed {orgs}")
432+
options = [f"{o.name:20s} ({o.id})" for o in orgs]
433+
434+
idx, _val = choose_one("Organisation", options)
435+
org = orgs[idx].id
436+
print(f"Selected organisation '{orgs[idx].name}' ({orgs[idx].id})")
437+
else:
438+
org = UUID(self.args.org)
439+
440+
applications = get_applications_by_organisation_id.sync(client=client, id=org)
428441

429442
if not isinstance(applications, list):
430443
print(f"Failed to retrieve application list {applications}")

0 commit comments

Comments
 (0)