Skip to content

Commit

Permalink
feat(cli): sort lists based on human-readable names
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain authored and ankitrgadiya committed Feb 7, 2023
1 parent 363fd87 commit 6f46cc1
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions riocli/auth/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def select_project(config: Configuration, project: str = None) -> None:
project_guid = project if project.startswith('project-') else find_project_guid(client, project)

projects = client.list_projects()
# Sort projects based on their names for an easier selection
projects = sorted(projects, key=lambda p: p.name.lower())
project_map = dict()

for project in projects:
Expand Down
1 change: 1 addition & 0 deletions riocli/deployment/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def list_deployments(device: str, phase: typing.List[str]) -> None:
try:
client = new_client()
deployments = client.get_all_deployments(device_id=device, phases=phase)
deployments = sorted(deployments, key=lambda d: d.name.lower())
display_deployment_list(deployments, show_header=True)
except Exception as e:
click.secho(str(e), fg='red')
Expand Down
1 change: 1 addition & 0 deletions riocli/device/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def list_devices() -> None:
try:
client = new_client()
devices = client.get_all_devices()
devices = sorted(devices, key=lambda d: d.name.lower())
_display_device_list(devices, show_header=True)
except Exception as e:
click.secho(str(e), fg='red')
Expand Down
1 change: 1 addition & 0 deletions riocli/disk/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def list_disks() -> None:
"""
try:
disks = _api_call(HttpMethod.GET)
disks = sorted(disks, key=lambda d: d['name'].lower())
_display_disk_list(disks, show_header=True)
except Exception as e:
click.secho(str(e), fg='red')
Expand Down
5 changes: 3 additions & 2 deletions riocli/network/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def list_networks(network: str) -> None:
if network in ['native', 'both']:
networks += client.list_native_networks()

networks = sorted(networks, key=lambda n: n.name.lower())
_display_network_list(networks, show_header=True)
except Exception as e:
click.secho(str(e), fg='red')
Expand All @@ -48,7 +49,7 @@ def _display_network_list(
show_header: bool = True,
) -> None:
if show_header:
click.secho('{:29} {:<15} {:8} {:8} {:20}'.
click.secho('{:29} {:<25} {:8} {:8} {:20}'.
format('Network ID', 'Network Name', 'Runtime', 'Type', 'Phase'),
fg='yellow')

Expand All @@ -64,5 +65,5 @@ def _display_network_list(

if phase and phase == DeploymentPhaseConstants.DEPLOYMENT_STOPPED.value:
continue
click.secho('{:29} {:<15} {:8} {:8} {:20}'.
click.secho('{:29} {:<25} {:8} {:8} {:20}'.
format(network.guid, network.name, network.runtime, network_type, phase))
1 change: 1 addition & 0 deletions riocli/package/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ def _display_package_list(
description = description[:truncate_limit] + '..'
if len(name) > truncate_limit:
name = name[:truncate_limit] + '..'

click.echo('{:30} {:10} {:34} {:<48}'.
format(name, package.packageVersion, package.packageId, description))
2 changes: 2 additions & 0 deletions riocli/project/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def list_project(ctx: click.Context) -> None:
try:
client = new_client(with_project=False)
projects = client.list_projects()
projects = sorted(projects, key=lambda p: p.name.lower())
current = ctx.obj.data.get('project_id', None)
_display_project_list(projects, current, show_header=True)
except Exception as e:
Expand All @@ -45,5 +46,6 @@ def _display_project_list(projects: typing.List[Project], current: str = None, s
fg = None
if project.guid == current:
fg = 'green'

click.secho('{:40} {:<25} {:<24} {:40}'.format(project.guid, project.name,
project.created_at, project.creator), fg=fg)
1 change: 1 addition & 0 deletions riocli/secret/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def list_secrets(secret_type: typing.Union[str, typing.Tuple[str]]) -> None:
try:
client = new_client()
secrets = client.list_secrets()
secrets = sorted(secrets, key=lambda s: s.name.lower())
_display_secret_list(secrets, secret_type, show_header=True)
except Exception as e:
click.secho(str(e), fg='red')
Expand Down

0 comments on commit 6f46cc1

Please sign in to comment.