Skip to content

Commit 9fda2bb

Browse files
committed
Merge branch 'master' into autocompleter
2 parents 13bb065 + 7944147 commit 9fda2bb

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

examples/subcommands.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
22
# coding=utf-8
3-
# PYTHON_ARGCOMPLETE_OK
43
"""A simple example demonstrating how to use Argparse to support subcommands.
54
65
76
This example shows an easy way for a single command to have many subcommands, each of which takes different arguments
87
and provides separate contextual help.
98
"""
109
import argparse
10+
import cmd2
1111

1212
sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball']
1313

@@ -19,10 +19,7 @@
1919
parser_foo = base_subparsers.add_parser('foo', help='foo help')
2020
parser_foo.add_argument('-x', type=int, default=1, help='integer')
2121
parser_foo.add_argument('y', type=float, help='float')
22-
input_file = parser_foo.add_argument('input_file', type=str, help='Input File')
23-
if __name__ == '__main__':
24-
from cmd2.argcomplete_bridge import bash_complete
25-
bash_complete(input_file)
22+
parser_foo.add_argument('input_file', type=str, help='Input File')
2623

2724
# create the parser for the "bar" subcommand
2825
parser_bar = base_subparsers.add_parser('bar', help='bar help')
@@ -39,28 +36,12 @@
3936
sport_arg = parser_sport.add_argument('sport', help='Enter name of a sport')
4037
setattr(sport_arg, 'arg_choices', sport_item_strs)
4138

42-
# Handle bash completion if it's installed
43-
try:
44-
# only move forward if we can import CompletionFinder and AutoCompleter
45-
from cmd2.argcomplete_bridge import CompletionFinder
46-
from cmd2.argparse_completer import AutoCompleter
47-
if __name__ == '__main__':
48-
completer = CompletionFinder()
49-
completer(base_parser, AutoCompleter(base_parser))
50-
except ImportError:
51-
pass
52-
53-
54-
# Intentionally below the bash completion code to reduce tab completion lag
55-
import cmd2
56-
5739

5840
class SubcommandsExample(cmd2.Cmd):
5941
"""
6042
Example cmd2 application where we a base command which has a couple subcommands
6143
and the "sport" subcommand has tab completion enabled.
6244
"""
63-
6445
def __init__(self):
6546
super().__init__()
6647

tests/test_cmd2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,3 +1739,12 @@ def test_parseline(base_app):
17391739
assert command == 'command'
17401740
assert args == "with 'partially completed quotes"
17411741
assert line == statement.strip()
1742+
1743+
1744+
def test_readline_remove_history_item(base_app):
1745+
from cmd2.rl_utils import readline
1746+
assert readline.get_current_history_length() == 0
1747+
readline.add_history('this is a test')
1748+
assert readline.get_current_history_length() == 1
1749+
readline.remove_history_item(0)
1750+
assert readline.get_current_history_length() == 0

0 commit comments

Comments
 (0)