From cbc96d77c09a3ec6d6bfe143e15735d1c7281a25 Mon Sep 17 00:00:00 2001 From: RonRothman Date: Mon, 14 Sep 2020 12:04:42 -0400 Subject: [PATCH] Sort the list of roles when they're presented for selection. The main benefit is that similar roles (e.g. same AWS account) will be adjacent. --- aws_google_auth/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws_google_auth/util.py b/aws_google_auth/util.py index 4aacac6..22f7895 100644 --- a/aws_google_auth/util.py +++ b/aws_google_auth/util.py @@ -43,7 +43,7 @@ def pick_a_role(roles, aliases=None, account=None): enriched_roles_tab.append([i + 1, role_property[0], role_property[1]]) while True: - print(tabulate(enriched_roles_tab, headers=['No', 'AWS account', 'Role'], )) + print(tabulate(sorted(enriched_roles_tab), headers=['No', 'AWS account', 'Role'], )) prompt = 'Type the number (1 - {:d}) of the role to assume: '.format(len(enriched_roles)) choice = Util.get_input(prompt) @@ -53,7 +53,7 @@ def pick_a_role(roles, aliases=None, account=None): print("Invalid choice, try again.") else: while True: - for i, role in enumerate(filtered_roles): + for i, role in enumerate(sorted(filtered_roles)): print("[{:>3d}] {}".format(i + 1, role)) prompt = 'Type the number (1 - {:d}) of the role to assume: '.format(len(filtered_roles))