diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-20 21:01:28 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-20 21:01:28 -0400 |
commit | c86f6c7ec9d8a852abb2cd2d5a10b8bc851fef8b (patch) | |
tree | 6e202c2fcb2acdabe5da7afb2726143154bd6d61 /cmd2/argparse_completer.py | |
parent | b902a49d174578e0f17336eeb2e0598b8167c4ee (diff) | |
download | cmd2-git-c86f6c7ec9d8a852abb2cd2d5a10b8bc851fef8b.tar.gz |
Sorting unsorted numbers list in ascending order in AutoCompleter
Diffstat (limited to 'cmd2/argparse_completer.py')
-rw-r--r-- | cmd2/argparse_completer.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index e7f3a0e2..41cff0dd 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -7,6 +7,7 @@ See the header of argparse_custom.py for instructions on how to use these featur """ import argparse +import numbers import shutil from typing import List, Union @@ -499,6 +500,11 @@ class AutoCompleter(object): # Since arg_choices can be any iterable type, convert to a list arg_choices = list(arg_choices) + # If these choices are numbers, and have not yet been sorted, then sort them now + if not self._cmd2_app.matches_sorted and all(isinstance(x, numbers.Number) for x in arg_choices): + arg_choices.sort() + self._cmd2_app.matches_sorted = True + # Since choices can be various types like int, we must convert them to strings for index, choice in enumerate(arg_choices): if not isinstance(choice, str): |