Skip to content

Commit ccef0b4

Browse files
authored
Merge pull request #115 from python-cmd2/redundant_commands
list command was redundant with history command
2 parents a0d829e + b70b850 commit ccef0b4

8 files changed

Lines changed: 76 additions & 76 deletions

File tree

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
News
22
====
33

4+
0.7.3
5+
-----
6+
7+
*Release date: TBD*
8+
9+
* Bug fixes
10+
* Fixed a bug in display a span of history items when only an end index is supplied
11+
* Enhancements
12+
* Added the ability to exclude commands from the help menu (**eof** included by default)
13+
* Redundant list command removed and features merged into history command
14+
415
0.7.2
516
-----
617

cmd2.py

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,12 @@ def do_cmdenvironment(self, args):
11211121
Commands may be terminated with: {}
11221122
Command-line arguments allowed: {}
11231123
Output redirection and pipes allowed: {}
1124-
Settable parameters: {}\n""".format(not self.case_insensitive, str(self.terminators),
1125-
self.allow_cli_args,
1126-
self.allow_redirection, ' '.join(self.settable)))
1124+
Parsing of @options commands:
1125+
Use POSIX-style argument parser (vs Windows): {}
1126+
Strip Quotes when using Windows-style argument parser: {}
1127+
Use a list of arguments instead of a single argument string: {}
1128+
\n""".format(not self.case_insensitive, str(self.terminators), self.allow_cli_args, self.allow_redirection,
1129+
POSIX_SHLEX, STRIP_QUOTES_FOR_NON_POSIX, USE_ARG_LIST))
11271130

11281131
def do_help(self, arg):
11291132
"""List available commands with "help" or detailed help with "help cmd"."""
@@ -1592,7 +1595,8 @@ def do_history(self, arg, opts):
15921595
15931596
| no arg: list all
15941597
| arg is integer: list one history item, by index
1595-
| arg is string: string search
1598+
| a..b, a:b, a:, ..b -> list history items by a span of indices (inclusive)
1599+
| arg is string: list all commands matching string search
15961600
| arg is /enclosed in forward-slashes/: regular expression search
15971601
"""
15981602
# If arguments are being passed as a list instead of as a string
@@ -1602,10 +1606,20 @@ def do_history(self, arg, opts):
16021606
else:
16031607
arg = ''
16041608

1609+
# If an argument was supplied, then retrieve partial contents of the history
16051610
if arg:
1606-
history = self.history.get(arg)
1611+
# If a character indicating a slice is present, retrieve a slice of the history
1612+
if '..' in arg or ':' in arg:
1613+
# Get a slice of history
1614+
history = self.history.span(arg)
1615+
else:
1616+
# Get item(s) from history by index or string search
1617+
history = self.history.get(arg)
16071618
else:
1619+
# If no arg given, then retrieve the entire history
16081620
history = self.history
1621+
1622+
# Display the history items retrieved
16091623
for hi in history:
16101624
if opts.script:
16111625
self.poutput(hi)
@@ -1628,38 +1642,6 @@ def _last_matching(self, arg):
16281642
except IndexError:
16291643
return None
16301644

1631-
def do_list(self, arg):
1632-
"""list [arg]: lists command(s) from history in a flexible/searchable way.
1633-
1634-
:param arg: str - behavior varies as follows:
1635-
1636-
* no arg -> list most recent command
1637-
* arg is integer -> list one history item, by index
1638-
* a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end)
1639-
* arg is string -> list all commands matching string search
1640-
* arg is /enclosed in forward-slashes/ -> regular expression search
1641-
"""
1642-
try:
1643-
history = self.history.span(arg or '-1')
1644-
except IndexError:
1645-
history = self.history.search(arg)
1646-
for hi in history:
1647-
self.poutput(hi.pr())
1648-
1649-
def help_list(self):
1650-
"""Print help for do_list()."""
1651-
help_str = """Lists command(s) from history in a flexible/searchable way.
1652-
1653-
Usage: list [arg]
1654-
1655-
Where arg is:
1656-
no arg -> list most recent command
1657-
arg is integer -> list one history item, by index
1658-
a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end)
1659-
arg is string -> list all commands matching string search
1660-
arg is /enclosed in forward-slashes/ -> regular expression search"""
1661-
self.stdout.write("{}\n".format(help_str))
1662-
16631645
def do_edit(self, arg):
16641646
"""Edit a file or command in a text editor.
16651647
@@ -2170,7 +2152,7 @@ def span(self, raw):
21702152
raise IndexError
21712153
if not results.group('separator'):
21722154
return [self[self._to_index(results.group('start'))]]
2173-
start = self._to_index(results.group('start'))
2155+
start = self._to_index(results.group('start')) or 0 # Ensure start is not None
21742156
end = self._to_index(results.group('end'))
21752157
reverse = False
21762158
if end is not None:

docs/freefeatures.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ also provide `bash-like history list editing`_.
220220

221221
.. automethod:: cmd2.Cmd.do_history
222222

223-
.. automethod:: cmd2.Cmd.do_list
224-
225223
.. automethod:: cmd2.Cmd.do_run
226224

227225
Quitting the application

examples/exampleSession.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
Documented commands (type help <topic>):
55
========================================
6-
_relative_load edit help list orate py run say shell show
7-
cmdenvironment eof history load pause quit save set shortcuts speak
6+
_relative_load edit history orate py run say shell show
7+
cmdenvironment help load pause quit save set shortcuts speak
88

99
(Cmd) help say
1010
Repeats what you tell me to.

tests/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
# Help text for base cmd2.Cmd application
1616
BASE_HELP = """Documented commands (type help <topic>):
1717
========================================
18-
_relative_load edit history load py run set shortcuts
19-
cmdenvironment help list pause quit save shell show
18+
_relative_load edit history pause quit save shell show
19+
cmdenvironment help load py run set shortcuts
2020
"""
2121

2222
# Help text for the history command
2323
HELP_HISTORY = """history [arg]: lists past commands issued
2424
2525
| no arg: list all
2626
| arg is integer: list one history item, by index
27-
| arg is string: string search
27+
| a..b, a:b, a:, ..b -> list history items by a span of indices (inclusive)
28+
| arg is string: list all commands matching string search
2829
| arg is /enclosed in forward-slashes/: regular expression search
2930
3031
Usage: history [options] (limit on which commands to include)

tests/test_cmd2.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,48 +142,62 @@ def test_base_history(base_app):
142142
""")
143143
assert out == expected
144144

145-
146-
def test_base_list(base_app):
145+
def test_history_with_string_argument(base_app):
147146
run_cmd(base_app, 'help')
148147
run_cmd(base_app, 'shortcuts')
149-
out = run_cmd(base_app, 'list')
148+
run_cmd(base_app, 'help history')
149+
out = run_cmd(base_app, 'history help')
150150
expected = normalize("""
151-
-------------------------[2]
152-
shortcuts
151+
-------------------------[1]
152+
help
153+
-------------------------[3]
154+
help history
153155
""")
154156
assert out == expected
155157

156158

157-
def test_list_with_string_argument(base_app):
159+
def test_history_with_integer_argument(base_app):
158160
run_cmd(base_app, 'help')
159161
run_cmd(base_app, 'shortcuts')
160-
run_cmd(base_app, 'help list')
161-
out = run_cmd(base_app, 'list help')
162+
out = run_cmd(base_app, 'history 1')
162163
expected = normalize("""
163164
-------------------------[1]
164165
help
165-
-------------------------[3]
166-
help list
167166
""")
168167
assert out == expected
169168

170169

171-
def test_list_with_integer_argument(base_app):
170+
def test_history_with_integer_span(base_app):
172171
run_cmd(base_app, 'help')
173172
run_cmd(base_app, 'shortcuts')
174-
out = run_cmd(base_app, 'list 1')
173+
run_cmd(base_app, 'help history')
174+
out = run_cmd(base_app, 'history 1..2')
175175
expected = normalize("""
176176
-------------------------[1]
177177
help
178+
-------------------------[2]
179+
shortcuts
178180
""")
179181
assert out == expected
180182

183+
def test_history_with_span_start(base_app):
184+
run_cmd(base_app, 'help')
185+
run_cmd(base_app, 'shortcuts')
186+
run_cmd(base_app, 'help history')
187+
out = run_cmd(base_app, 'history 2:')
188+
expected = normalize("""
189+
-------------------------[2]
190+
shortcuts
191+
-------------------------[3]
192+
help history
193+
""")
194+
assert out == expected
181195

182-
def test_list_with_integer_span(base_app):
196+
def test_history_with_span_end(base_app):
183197
run_cmd(base_app, 'help')
184198
run_cmd(base_app, 'shortcuts')
185-
run_cmd(base_app, 'help list')
186-
out = run_cmd(base_app, 'list 1..2')
199+
run_cmd(base_app, 'help history')
200+
out = run_cmd(base_app, 'history :2')
187201
expected = normalize("""
188202
-------------------------[1]
189203
help
@@ -201,17 +215,13 @@ def test_base_cmdenvironment(base_app):
201215
Commands may be terminated with: [';']
202216
Command-line arguments allowed: True
203217
Output redirection and pipes allowed: True
218+
Parsing of @options commands:
219+
Use POSIX-style argument parser (vs Windows): False
220+
Strip Quotes when using Windows-style argument parser: True
221+
Use a list of arguments instead of a single argument string: False
222+
204223
""")
205-
assert out[:4] == expected[:4]
206-
assert out[4].strip().startswith('Settable parameters: ')
207-
208-
# Settable parameters can be listed in any order, so need to validate carefully using unordered sets
209-
settable_params = {'continuation_prompt', 'default_file_name', 'prompt', 'abbrev', 'quiet', 'case_insensitive',
210-
'colors', 'echo', 'timing', 'editor', 'feedback_to_output', 'debug', 'autorun_on_edit',
211-
'locals_in_py'}
212-
out_params = set(out[4].split("Settable parameters: ")[1].split())
213-
assert settable_params == out_params
214-
224+
assert out == expected
215225

216226
def test_base_load(base_app, request):
217227
test_dir = os.path.dirname(request.module.__file__)

tests/test_transcript.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ def test_base_with_transcript(_cmdline_app):
106106
107107
Documented commands (type help <topic>):
108108
========================================
109-
_relative_load help load py save shell speak
110-
cmdenvironment history orate quit say shortcuts
111-
edit list pause run set show
109+
_relative_load edit history orate py run say shell show
110+
cmdenvironment help load pause quit save set shortcuts speak
112111
113112
(Cmd) help say
114113
Repeats what you tell me to.

tests/transcript.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
Documented commands (type help <topic>):
44
========================================
5-
_relative_load help load py save shell speak
6-
cmdenvironment history orate quit say shortcuts
7-
edit list pause run set show
5+
_relative_load edit history orate py run say shell show
6+
cmdenvironment help load pause quit save set shortcuts speak
87

98
(Cmd) help say
109
Repeats what you tell me to.

0 commit comments

Comments
 (0)