diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-03 17:26:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-03 17:26:10 -0400 |
commit | ccef0b4193297c0b88e8add373f6a49126ffe772 (patch) | |
tree | 78fbd51ee75d14e0963b712f843d473481611fff /cmd2.py | |
parent | a0d829e4105cd431198feb43534adaf953b090ba (diff) | |
parent | b70b85067450b529a19a5a4bdbc8646c88f4e342 (diff) | |
download | cmd2-git-ccef0b4193297c0b88e8add373f6a49126ffe772.tar.gz |
Merge pull request #115 from python-cmd2/redundant_commands
list command was redundant with history command
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 58 |
1 files changed, 20 insertions, 38 deletions
@@ -1121,9 +1121,12 @@ class Cmd(cmd.Cmd): Commands may be terminated with: {} Command-line arguments allowed: {} Output redirection and pipes allowed: {} - Settable parameters: {}\n""".format(not self.case_insensitive, str(self.terminators), - self.allow_cli_args, - self.allow_redirection, ' '.join(self.settable))) + Parsing of @options commands: + Use POSIX-style argument parser (vs Windows): {} + Strip Quotes when using Windows-style argument parser: {} + Use a list of arguments instead of a single argument string: {} + \n""".format(not self.case_insensitive, str(self.terminators), self.allow_cli_args, self.allow_redirection, + POSIX_SHLEX, STRIP_QUOTES_FOR_NON_POSIX, USE_ARG_LIST)) def do_help(self, arg): """List available commands with "help" or detailed help with "help cmd".""" @@ -1592,7 +1595,8 @@ class Cmd(cmd.Cmd): | no arg: list all | arg is integer: list one history item, by index - | arg is string: string search + | a..b, a:b, a:, ..b -> list history items by a span of indices (inclusive) + | arg is string: list all commands matching string search | arg is /enclosed in forward-slashes/: regular expression search """ # If arguments are being passed as a list instead of as a string @@ -1602,10 +1606,20 @@ class Cmd(cmd.Cmd): else: arg = '' + # If an argument was supplied, then retrieve partial contents of the history if arg: - history = self.history.get(arg) + # If a character indicating a slice is present, retrieve a slice of the history + if '..' in arg or ':' in arg: + # Get a slice of history + history = self.history.span(arg) + else: + # Get item(s) from history by index or string search + history = self.history.get(arg) else: + # If no arg given, then retrieve the entire history history = self.history + + # Display the history items retrieved for hi in history: if opts.script: self.poutput(hi) @@ -1628,38 +1642,6 @@ class Cmd(cmd.Cmd): except IndexError: return None - def do_list(self, arg): - """list [arg]: lists command(s) from history in a flexible/searchable way. - - :param arg: str - behavior varies as follows: - - * no arg -> list most recent command - * arg is integer -> list one history item, by index - * a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end) - * arg is string -> list all commands matching string search - * arg is /enclosed in forward-slashes/ -> regular expression search - """ - try: - history = self.history.span(arg or '-1') - except IndexError: - history = self.history.search(arg) - for hi in history: - self.poutput(hi.pr()) - - def help_list(self): - """Print help for do_list().""" - help_str = """Lists command(s) from history in a flexible/searchable way. - - Usage: list [arg] - - Where arg is: - no arg -> list most recent command - arg is integer -> list one history item, by index - a..b, a:b, a:, ..b -> list spans from a (or start) to b (or end) - arg is string -> list all commands matching string search - arg is /enclosed in forward-slashes/ -> regular expression search""" - self.stdout.write("{}\n".format(help_str)) - def do_edit(self, arg): """Edit a file or command in a text editor. @@ -2170,7 +2152,7 @@ class History(list): raise IndexError if not results.group('separator'): return [self[self._to_index(results.group('start'))]] - start = self._to_index(results.group('start')) + start = self._to_index(results.group('start')) or 0 # Ensure start is not None end = self._to_index(results.group('end')) reverse = False if end is not None: |