Skip to content

Commit dcd5449

Browse files
smandondmerejkowsky
authored andcommitted
Optional sort on ask_choice
1 parent c0c24e4 commit dcd5449

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cli_ui/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ def ask_password(*question: Token) -> str:
494494

495495

496496
def ask_choice(
497-
*prompt: Token, choices: List[Any], func_desc: Optional[FuncDesc] = None
498-
) -> Any:
497+
*prompt: Token, choices: List[Any], func_desc: Optional[FuncDesc] = None,
498+
sort: Optional[bool] = True) -> Any:
499499
"""Ask the user to choose from a list of choices.
500500
501501
:return: the selected choice
@@ -514,7 +514,8 @@ def ask_choice(
514514
func_desc = lambda x: str(x)
515515
tokens = get_ask_tokens(prompt)
516516
info(*tokens)
517-
choices.sort(key=func_desc)
517+
if sort:
518+
choices.sort(key=func_desc)
518519
for i, choice in enumerate(choices, start=1):
519520
choice_desc = func_desc(choice)
520521
info(" ", blue, "%i" % i, reset, choice_desc)

0 commit comments

Comments
 (0)