summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-03 19:56:25 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-03 19:56:25 -0400
commit7c17d8bbf006e17f0104b6d9d35fc67ca4f235fd (patch)
treeb6112be31428ad363c74a420cda5a70d2bd7f5ac /cmd2.py
parentd092e61815f9132b7acd3859563c143ac8ddda56 (diff)
downloadcmd2-git-7c17d8bbf006e17f0104b6d9d35fc67ca4f235fd.tar.gz
Fixed a few bugs and examples
Bug fixes: - case_insensitive is no longer a runtime-settable parameter, but it was still listed as such - Fixed a recursive loop bug when abbreviated commands are enabled and it could get stuck in the editor forever - Added additional command abbreviations to the "exclude from history" list - Fixed argparse_example.py and pirate.py examples Other changes: - Organized all attributes used to configure the ParserManager into a single location - Set the default value of "abbrev" to False (which controls whether or not abbreviated commands are allowed) - With good tab-completion of command names, using abbreviated commands isn't a particularly useful feature - And it can create problems
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/cmd2.py b/cmd2.py
index d0fcad42..59b2adbc 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -400,32 +400,29 @@ class Cmd(cmd.Cmd):
Line-oriented command interpreters are often useful for test harnesses, internal tools, and rapid prototypes.
"""
- # Attributes which are NOT dynamically settable at runtime
- allow_cli_args = True # Should arguments passed on the command-line be processed as commands?
- allow_redirection = True # Should output redirection and pipes be allowed
+ # Attributes used to configure the ParserManager (all are not dynamically settable at runtime)
blankLinesAllowed = False
- commentGrammars = pyparsing.Or(
- [pyparsing.pythonStyleComment, pyparsing.cStyleComment]
- )
+ case_insensitive = True # Commands recognized regardless of case
+ commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment])
commentInProgress = pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd ^ '*/')
-
- default_to_shell = False # Attempt to run unrecognized commands as shell commands
- excludeFromHistory = '''run r list l history hi ed edit li eof'''.split()
- exclude_from_help = ['do_eof'] # Commands to exclude from the help menu
-
- # make sure your terminators are not in legalChars!
legalChars = u'!#$%.:?@_-' + pyparsing.alphanums + pyparsing.alphas8bit
multilineCommands = [] # NOTE: Multiline commands can never be abbreviated, even if abbrev is True
prefixParser = pyparsing.Empty()
- redirector = '>' # for sending output to file
- reserved_words = []
+ redirector = '>' # for sending output to file
shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
- terminators = [';']
+ terminators = [';'] # make sure your terminators are not in legalChars!
+
+ # Attributes which are NOT dynamically settable at runtime
+ allow_cli_args = True # Should arguments passed on the command-line be processed as commands?
+ allow_redirection = True # Should output redirection and pipes be allowed
+ default_to_shell = False # Attempt to run unrecognized commands as shell commands
+ excludeFromHistory = '''run ru r history histor histo hist his hi h edit edi ed e eof eo'''.split()
+ exclude_from_help = ['do_eof'] # Commands to exclude from the help menu
+ reserved_words = []
# Attributes which ARE dynamically settable at runtime
- abbrev = True # Abbreviated commands recognized
+ abbrev = False # Abbreviated commands recognized
autorun_on_edit = False # Should files automatically run after editing (doesn't apply to commands)
- case_insensitive = True # Commands recognized regardless of case
colors = (platform.system() != 'Windows')
continuation_prompt = '> '
debug = False
@@ -448,7 +445,6 @@ class Cmd(cmd.Cmd):
# This starts out as a dictionary but gets converted to an OrderedDict sorted alphabetically by key
settable = {'abbrev': 'Accept abbreviated commands',
'autorun_on_edit': 'Automatically run files after editing',
- 'case_insensitive': 'Upper- and lower-case both OK',
'colors': 'Colorized output (*nix only)',
'continuation_prompt': 'On 2nd+ line of input',
'debug': 'Show full error stack on error',