summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-05-19 15:54:08 -0400
committerEric Lin <anselor@gmail.com>2018-05-19 15:54:08 -0400
commit1c1da0273faf3ab2316b4af9281cf15869b3da20 (patch)
tree100044bd28c56ab2b30f356e3ecfbd02af78d48b /examples
parentf44871b5d055651bb4991580b64b18b87568fd7a (diff)
downloadcmd2-git-1c1da0273faf3ab2316b4af9281cf15869b3da20.tar.gz
Changed some unit tests to use pytest-mock instead of mocker/monkeypatch because they were failing for me.
Added detection of ==SUPPRESS== in subcommand group names to avoid printing it in the help hint. Added some examples to tab_autocompletion to demonstrate how to tie in to cmd2 path_complete
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/tab_autocompletion.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/examples/tab_autocompletion.py b/examples/tab_autocompletion.py
index 65679e4f..adfe9702 100755
--- a/examples/tab_autocompletion.py
+++ b/examples/tab_autocompletion.py
@@ -235,17 +235,22 @@ class TabCompleteExample(cmd2.Cmd):
actor_action = vid_movies_add_parser.add_argument('actor', help='Actors', nargs='*')
vid_movies_load_parser = vid_movies_commands_subparsers.add_parser('load')
- movie_file_action = vid_movies_load_parser.add_argument('movie_file', help='Movie database')
+ vid_movie_file_action = vid_movies_load_parser.add_argument('movie_file', help='Movie database')
+
+ vid_movies_read_parser = vid_movies_commands_subparsers.add_parser('read')
+ vid_movie_fread_action = vid_movies_read_parser.add_argument('movie_file', help='Movie database')
# tag the action objects with completion providers. This can be a collection or a callable
setattr(director_action, argparse_completer.ACTION_ARG_CHOICES, static_list_directors)
setattr(actor_action, argparse_completer.ACTION_ARG_CHOICES, 'instance_query_actors')
# tag the file property with a custom completion function 'delimeter_complete' provided by cmd2.
- setattr(movie_file_action, argparse_completer.ACTION_ARG_CHOICES,
+ setattr(vid_movie_file_action, argparse_completer.ACTION_ARG_CHOICES,
('delimiter_complete',
{'delimiter': '/',
'match_against': file_list}))
+ setattr(vid_movie_fread_action, argparse_completer.ACTION_ARG_CHOICES,
+ ('path_complete', [False, False]))
vid_movies_delete_parser = vid_movies_commands_subparsers.add_parser('delete')
@@ -324,6 +329,9 @@ class TabCompleteExample(cmd2.Cmd):
movies_delete_parser = movies_commands_subparsers.add_parser('delete')
+ movies_load_parser = movies_commands_subparsers.add_parser('load')
+ movie_file_action = movies_load_parser.add_argument('movie_file', help='Movie database')
+
shows_parser = media_types_subparsers.add_parser('shows')
shows_parser.set_defaults(func=_do_media_shows)
@@ -351,7 +359,8 @@ class TabCompleteExample(cmd2.Cmd):
def complete_media(self, text, line, begidx, endidx):
""" Adds tab completion to media"""
choices = {'actor': query_actors, # function
- 'director': TabCompleteExample.static_list_directors # static list
+ 'director': TabCompleteExample.static_list_directors, # static list
+ 'movie_file': (self.path_complete, [False, False])
}
completer = argparse_completer.AutoCompleter(TabCompleteExample.media_parser, arg_choices=choices)