summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/cmd2.py b/cmd2.py
index 1c2daf7b..4fa2a0df 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -788,18 +788,14 @@ class Cmd(cmd.Cmd):
commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment])
commentInProgress = pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd ^ '*/')
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
- shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
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 eos'''.split()
- exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load'] # Commands to exclude from the help menu
reserved_words = []
# Attributes which ARE dynamically settable at runtime
@@ -869,13 +865,21 @@ class Cmd(cmd.Cmd):
# Call super class constructor. Need to do it in this way for Python 2 and 3 compatibility
cmd.Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout)
+ self.multiline_commands = [] # NOTE: Multiline commands can never be abbreviated, even if abbrev is True
+ self.shortcuts = {'?': 'help', '!': 'shell', '@': 'load', '@@': '_relative_load'}
+
+ # Commands to exclude from the help menu or history command
+ self.exclude_from_help = ['do_eof', 'do_eos', 'do__relative_load']
+ self.exclude_from_history = '''history histor histo hist his hi h edit edi ed e eof eo eos'''.split()
+
self._finalize_app_parameters()
+
self.initial_stdout = sys.stdout
self.history = History()
self.pystate = {}
self.keywords = self.reserved_words + [fname[3:] for fname in dir(self) if fname.startswith('do_')]
self.parser_manager = ParserManager(redirector=self.redirector, terminators=self.terminators,
- multilineCommands=self.multilineCommands,
+ multilineCommands=self.multiline_commands,
legalChars=self.legalChars, commentGrammars=self.commentGrammars,
commentInProgress=self.commentInProgress,
case_insensitive=self.case_insensitive,
@@ -1390,7 +1394,7 @@ class Cmd(cmd.Cmd):
result = target
else:
if self.abbrev: # accept shortened versions of commands
- funcs = [func for func in self.keywords if func.startswith(arg) and func not in self.multilineCommands]
+ funcs = [func for func in self.keywords if func.startswith(arg) and func not in self.multiline_commands]
if len(funcs) == 1:
result = 'do_' + funcs[0]
return result
@@ -1409,7 +1413,7 @@ class Cmd(cmd.Cmd):
return self.default(statement)
# Since we have a valid command store it in the history
- if statement.parsed.command not in self.excludeFromHistory:
+ if statement.parsed.command not in self.exclude_from_history:
self.history.append(statement.parsed.raw)
try: