summaryrefslogtreecommitdiff
path: root/examples/basic_completion.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2021-01-31 22:29:57 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2021-01-31 22:29:57 -0500
commitf456b802754c3d1095b488d670bebba21018d823 (patch)
treebf7011f585a8a35ab4cc7ff98aaeebed4de87f84 /examples/basic_completion.py
parent918200c02d392c17862fff81bbf58820ed15c725 (diff)
downloadcmd2-git-f456b802754c3d1095b488d670bebba21018d823.tar.gz
Add black for automatic code format
Diffstat (limited to 'examples/basic_completion.py')
-rwxr-xr-xexamples/basic_completion.py59
1 files changed, 26 insertions, 33 deletions
diff --git a/examples/basic_completion.py b/examples/basic_completion.py
index 83e71a50..aab7d3d1 100755
--- a/examples/basic_completion.py
+++ b/examples/basic_completion.py
@@ -13,9 +13,7 @@ familiar with argparse. The recommended approach for tab completing positional t
argparse-based completion. For an example integrating tab completion with argparse, see argparse_completion.py
"""
import functools
-from typing import (
- List,
-)
+from typing import List
import cmd2
@@ -24,14 +22,13 @@ food_item_strs = ['Pizza', 'Ham', 'Ham Sandwich', 'Potato']
sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball']
# This data is used to demonstrate delimiter_complete
-file_strs = \
- [
- '/home/user/file.db',
- '/home/user/file space.db',
- '/home/user/another.db',
- '/home/other user/maps.db',
- '/home/other user/tests.db'
- ]
+file_strs = [
+ '/home/user/file.db',
+ '/home/user/file space.db',
+ '/home/user/another.db',
+ '/home/other user/maps.db',
+ '/home/other user/tests.db',
+]
class BasicCompletion(cmd2.Cmd):
@@ -48,20 +45,17 @@ class BasicCompletion(cmd2.Cmd):
def complete_flag_based(self, text, line, begidx, endidx) -> List[str]:
"""Completion function for do_flag_based"""
- flag_dict = \
- {
- # Tab complete food items after -f and --food flags in command line
- '-f': food_item_strs,
- '--food': food_item_strs,
-
- # Tab complete sport items after -s and --sport flags in command line
- '-s': sport_item_strs,
- '--sport': sport_item_strs,
-
- # Tab complete using path_complete function after -p and --path flags in command line
- '-p': self.path_complete,
- '--path': self.path_complete,
- }
+ flag_dict = {
+ # Tab complete food items after -f and --food flags in command line
+ '-f': food_item_strs,
+ '--food': food_item_strs,
+ # Tab complete sport items after -s and --sport flags in command line
+ '-s': sport_item_strs,
+ '--sport': sport_item_strs,
+ # Tab complete using path_complete function after -p and --path flags in command line
+ '-p': self.path_complete,
+ '--path': self.path_complete,
+ }
return self.flag_based_complete(text, line, begidx, endidx, flag_dict=flag_dict)
@@ -71,12 +65,11 @@ class BasicCompletion(cmd2.Cmd):
def complete_index_based(self, text, line, begidx, endidx) -> List[str]:
"""Completion function for do_index_based"""
- index_dict = \
- {
- 1: food_item_strs, # Tab complete food items at index 1 in command line
- 2: sport_item_strs, # Tab complete sport items at index 2 in command line
- 3: self.path_complete, # Tab complete using path_complete function at index 3 in command line
- }
+ index_dict = {
+ 1: food_item_strs, # Tab complete food items at index 1 in command line
+ 2: sport_item_strs, # Tab complete sport items at index 2 in command line
+ 3: self.path_complete, # Tab complete using path_complete function at index 3 in command line
+ }
return self.index_based_complete(text, line, begidx, endidx, index_dict=index_dict)
@@ -85,8 +78,7 @@ class BasicCompletion(cmd2.Cmd):
self.poutput("Args: {}".format(statement.args))
# Use a partialmethod to set arguments to delimiter_complete
- complete_delimiter_complete = functools.partialmethod(cmd2.Cmd.delimiter_complete,
- match_against=file_strs, delimiter='/')
+ complete_delimiter_complete = functools.partialmethod(cmd2.Cmd.delimiter_complete, match_against=file_strs, delimiter='/')
def do_raise_error(self, statement: cmd2.Statement):
"""Demonstrates effect of raising CompletionError"""
@@ -105,5 +97,6 @@ class BasicCompletion(cmd2.Cmd):
if __name__ == '__main__':
import sys
+
app = BasicCompletion()
sys.exit(app.cmdloop())