diff options
author | kmvanbrunt <kmvanbrunt@gmail.com> | 2019-02-27 23:12:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 23:12:11 -0500 |
commit | d3208c84c72bc1f3280c80b9d9854f33631c6b61 (patch) | |
tree | 549bcd9171ae3c2ab91baa3a142e79957e27e576 /examples/tab_autocompletion.py | |
parent | 7b1b8b10e35b57a813369c9b23876d3615213026 (diff) | |
parent | 53c41ea5ff6eda6bba94938c16505e4db10c46b6 (diff) | |
download | cmd2-git-d3208c84c72bc1f3280c80b9d9854f33631c6b61.tar.gz |
Merge pull request #629 from python-cmd2/auto_complete_overhaul
Auto complete cleanup
Diffstat (limited to 'examples/tab_autocompletion.py')
-rwxr-xr-x | examples/tab_autocompletion.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/examples/tab_autocompletion.py b/examples/tab_autocompletion.py index 6dc9844d..aa28fc10 100755 --- a/examples/tab_autocompletion.py +++ b/examples/tab_autocompletion.py @@ -11,7 +11,7 @@ import itertools from typing import List import cmd2 -from cmd2 import argparse_completer +from cmd2 import argparse_completer, utils actors = ['Mark Hamill', 'Harrison Ford', 'Carrie Fisher', 'Alec Guinness', 'Peter Mayhew', 'Anthony Daniels', 'Adam Driver', 'Daisy Ridley', 'John Boyega', 'Oscar Isaac', @@ -113,11 +113,14 @@ class TabCompleteExample(cmd2.Cmd): """Demonstrates showing tabular hinting of tab completion information""" completions_with_desc = [] - for movie_id in self.MOVIE_DATABASE_IDS: + # Sort the movie id strings with a natural sort since they contain numbers + for movie_id in utils.natural_sort(self.MOVIE_DATABASE_IDS): if movie_id in self.MOVIE_DATABASE: movie_entry = self.MOVIE_DATABASE[movie_id] completions_with_desc.append(argparse_completer.CompletionItem(movie_id, movie_entry['title'])) + # Mark that we already sorted the matches + self.matches_sorted = True return completions_with_desc # This demonstrates a number of customizations of the AutoCompleter version of ArgumentParser @@ -378,7 +381,9 @@ class TabCompleteExample(cmd2.Cmd): 'director': TabCompleteExample.static_list_directors, # static list 'movie_file': (self.path_complete,) } - completer = argparse_completer.AutoCompleter(TabCompleteExample.media_parser, arg_choices=choices, cmd2_app=self) + completer = argparse_completer.AutoCompleter(TabCompleteExample.media_parser, + self, + arg_choices=choices) tokens, _ = self.tokens_for_completion(line, begidx, endidx) results = completer.complete_command(tokens, text, line, begidx, endidx) @@ -525,6 +530,7 @@ class TabCompleteExample(cmd2.Cmd): library_subcommand_groups = {'type': library_type_params} completer = argparse_completer.AutoCompleter(TabCompleteExample.library_parser, + self, subcmd_args_lookup=library_subcommand_groups) tokens, _ = self.tokens_for_completion(line, begidx, endidx) |