summaryrefslogtreecommitdiff
path: root/examples/argparse_completion.py
diff options
context:
space:
mode:
authorxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 17:21:33 -0800
committerxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 18:20:13 -0800
commit9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch)
tree567693115cc101efb9254a96d96d80e9f9ccd557 /examples/argparse_completion.py
parent03c65c60b39e369958b056c5c844d36d515c8a63 (diff)
downloadcmd2-git-ci_improvements.tar.gz
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml There are also some small changes to travis.yml and tasks.py to reduce some repeated configurations that should be consolidated into setup.cfg. Most other changes are automated by the linter scripts.
Diffstat (limited to 'examples/argparse_completion.py')
-rw-r--r--examples/argparse_completion.py56
1 files changed, 31 insertions, 25 deletions
diff --git a/examples/argparse_completion.py b/examples/argparse_completion.py
index e44533b3..39904dec 100644
--- a/examples/argparse_completion.py
+++ b/examples/argparse_completion.py
@@ -30,12 +30,7 @@ def completer_function(text: str, line: str, begidx: int, endidx: int) -> List[s
def choices_completion_item() -> List[CompletionItem]:
"""Return CompletionItem instead of strings. These give more context to what's being tab completed."""
- items = \
- {
- 1: "My item",
- 2: "Another item",
- 3: "Yet another item"
- }
+ items = {1: "My item", 2: "Another item", 3: "Yet another item"}
return [CompletionItem(item_id, description) for item_id, description in items.items()]
@@ -77,38 +72,48 @@ class ArgparseCompletion(Cmd):
raise CompletionError("debug must be true")
# Parser for example command
- example_parser = Cmd2ArgumentParser(description="Command demonstrating tab completion with argparse\n"
- "Notice even the flags of this command tab complete")
+ example_parser = Cmd2ArgumentParser(
+ description="Command demonstrating tab completion with argparse\n" "Notice even the flags of this command tab complete"
+ )
# Tab complete from a list using argparse choices. Set metavar if you don't
# want the entire choices list showing in the usage text for this command.
- example_parser.add_argument('--choices', choices=food_item_strs, metavar="CHOICE",
- help="tab complete using choices")
+ example_parser.add_argument('--choices', choices=food_item_strs, metavar="CHOICE", help="tab complete using choices")
# Tab complete from choices provided by a choices function and choices method
- example_parser.add_argument('--choices_function', choices_function=choices_function,
- help="tab complete using a choices_function")
- example_parser.add_argument('--choices_method', choices_method=choices_method,
- help="tab complete using a choices_method")
+ example_parser.add_argument(
+ '--choices_function', choices_function=choices_function, help="tab complete using a choices_function"
+ )
+ example_parser.add_argument('--choices_method', choices_method=choices_method, help="tab complete using a choices_method")
# Tab complete using a completer function and completer method
- example_parser.add_argument('--completer_function', completer_function=completer_function,
- help="tab complete using a completer_function")
- example_parser.add_argument('--completer_method', completer_method=Cmd.path_complete,
- help="tab complete using a completer_method")
+ example_parser.add_argument(
+ '--completer_function', completer_function=completer_function, help="tab complete using a completer_function"
+ )
+ example_parser.add_argument(
+ '--completer_method', completer_method=Cmd.path_complete, help="tab complete using a completer_method"
+ )
# Demonstrate raising a CompletionError while tab completing
- example_parser.add_argument('--completion_error', choices_method=choices_completion_error,
- help="raise a CompletionError while tab completing if debug is False")
+ example_parser.add_argument(
+ '--completion_error',
+ choices_method=choices_completion_error,
+ help="raise a CompletionError while tab completing if debug is False",
+ )
# Demonstrate returning CompletionItems instead of strings
- example_parser.add_argument('--completion_item', choices_function=choices_completion_item, metavar="ITEM_ID",
- descriptive_header="Description",
- help="demonstrate use of CompletionItems")
+ example_parser.add_argument(
+ '--completion_item',
+ choices_function=choices_completion_item,
+ metavar="ITEM_ID",
+ descriptive_header="Description",
+ help="demonstrate use of CompletionItems",
+ )
# Demonstrate use of arg_tokens dictionary
- example_parser.add_argument('--arg_tokens', choices_function=choices_arg_tokens,
- help="demonstrate use of arg_tokens dictionary")
+ example_parser.add_argument(
+ '--arg_tokens', choices_function=choices_arg_tokens, help="demonstrate use of arg_tokens dictionary"
+ )
@with_argparser(example_parser)
def do_example(self, _: argparse.Namespace) -> None:
@@ -118,5 +123,6 @@ class ArgparseCompletion(Cmd):
if __name__ == '__main__':
import sys
+
app = ArgparseCompletion()
sys.exit(app.cmdloop())