diff options
Diffstat (limited to 'examples/tab_autocompletion.py')
-rwxr-xr-x | examples/tab_autocompletion.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/examples/tab_autocompletion.py b/examples/tab_autocompletion.py index adfe9702..e2c5b3da 100755 --- a/examples/tab_autocompletion.py +++ b/examples/tab_autocompletion.py @@ -10,8 +10,7 @@ import argparse import itertools from typing import List -from cmd2 import cmd2, argparse_completer -from cmd2.cmd2 import with_argparser, with_category +import cmd2 actors = ['Mark Hamill', 'Harrison Ford', 'Carrie Fisher', 'Alec Guinness', 'Peter Mayhew', 'Anthony Daniels', 'Adam Driver', 'Daisy Ridley', 'John Boyega', 'Oscar Isaac', @@ -114,7 +113,7 @@ class TabCompleteExample(cmd2.Cmd): # - The help output for arguments with multiple flags or with append=True is more concise # - ACArgumentParser adds the ability to specify ranges of argument counts in 'nargs' - suggest_parser = argparse_completer.ACArgumentParser() + suggest_parser = cmd2.argparse_completer.ACArgumentParser() suggest_parser.add_argument('-t', '--type', choices=['movie', 'show'], required=True) suggest_parser.add_argument('-d', '--duration', nargs=(1, 2), action='append', @@ -122,8 +121,8 @@ class TabCompleteExample(cmd2.Cmd): '\tsingle value - maximum duration\n' '\t[a, b] - duration range') - @with_category(CAT_AUTOCOMPLETE) - @with_argparser(suggest_parser) + @cmd2.with_category(CAT_AUTOCOMPLETE) + @cmd2.with_argparser(suggest_parser) def do_suggest(self, args) -> None: """Suggest command demonstrates argparse customizations @@ -139,7 +138,7 @@ class TabCompleteExample(cmd2.Cmd): suggest_parser_hybrid = argparse.ArgumentParser() # This registers the custom narg range handling - argparse_completer.register_custom_actions(suggest_parser_hybrid) + cmd2.argparse_completer.register_custom_actions(suggest_parser_hybrid) suggest_parser_hybrid.add_argument('-t', '--type', choices=['movie', 'show'], required=True) suggest_parser_hybrid.add_argument('-d', '--duration', nargs=(1, 2), action='append', @@ -147,8 +146,8 @@ class TabCompleteExample(cmd2.Cmd): '\tsingle value - maximum duration\n' '\t[a, b] - duration range') - @with_category(CAT_AUTOCOMPLETE) - @with_argparser(suggest_parser_hybrid) + @cmd2.with_category(CAT_AUTOCOMPLETE) + @cmd2.with_argparser(suggest_parser_hybrid) def do_hybrid_suggest(self, args): if not args.type: self.do_help('orig_suggest') @@ -165,8 +164,8 @@ class TabCompleteExample(cmd2.Cmd): '\tsingle value - maximum duration\n' '\t[a, b] - duration range') - @with_argparser(suggest_parser_orig) - @with_category(CAT_AUTOCOMPLETE) + @cmd2.with_argparser(suggest_parser_orig) + @cmd2.with_category(CAT_AUTOCOMPLETE) def do_orig_suggest(self, args) -> None: if not args.type: self.do_help('orig_suggest') @@ -261,8 +260,8 @@ class TabCompleteExample(cmd2.Cmd): vid_shows_list_parser = vid_shows_commands_subparsers.add_parser('list') - @with_category(CAT_AUTOCOMPLETE) - @with_argparser(video_parser) + @cmd2.with_category(CAT_AUTOCOMPLETE) + @cmd2.with_argparser(video_parser) def do_video(self, args): """Video management command demonstrates multiple layers of subcommands being handled by AutoCompleter""" func = getattr(args, 'func', None) @@ -339,8 +338,8 @@ class TabCompleteExample(cmd2.Cmd): shows_list_parser = shows_commands_subparsers.add_parser('list') - @with_category(CAT_AUTOCOMPLETE) - @with_argparser(media_parser) + @cmd2.with_category(CAT_AUTOCOMPLETE) + @cmd2.with_argparser(media_parser) def do_media(self, args): """Media management command demonstrates multiple layers of subcommands being handled by AutoCompleter""" func = getattr(args, 'func', None) @@ -440,8 +439,8 @@ class TabCompleteExample(cmd2.Cmd): return self._filter_library(text, line, begidx, endidx, all_episodes, user_eps) return [] - @with_category(CAT_AUTOCOMPLETE) - @with_argparser(library_parser) + @cmd2.with_category(CAT_AUTOCOMPLETE) + @cmd2.with_argparser(library_parser) def do_library(self, args): """Media management command demonstrates multiple layers of subcommands being handled by AutoCompleter""" func = getattr(args, 'func', None) |