summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-16 17:38:05 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-16 17:38:05 -0400
commit6b388ede0d1cc77a587164010cd0c47aa6ec7052 (patch)
treec0ca71c520f6451d1f12666be8790ba3387a6ed9 /cmd2/cmd2.py
parent8cf0b30af678717160a6c53cc7c0c84aa007c42f (diff)
downloadcmd2-git-6b388ede0d1cc77a587164010cd0c47aa6ec7052.tar.gz
Aliases are now stored within the StatementParser instance
Also: - Added read-only aliases property to cmd2.Cmd to get aliases from the StatementParser - Added a setter for the allow_redirection property in cmd2.Cmd - Made some initialization code more self-documenting
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 0c789e5f..e7ada8cd 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -370,7 +370,6 @@ class Cmd(cmd.Cmd):
self.exclude_from_history = '''history edit eof eos'''.split()
# Command aliases and macros
- self.aliases = dict()
self.macros = dict()
self.initial_stdout = sys.stdout
@@ -385,7 +384,6 @@ class Cmd(cmd.Cmd):
self.statement_parser = StatementParser(allow_redirection=allow_redirection,
terminators=terminators,
multiline_commands=multiline_commands,
- aliases=self.aliases,
shortcuts=shortcuts)
self._transcript_files = transcript_files
@@ -541,15 +539,25 @@ class Cmd(cmd.Cmd):
return utils.strip_ansi(self.prompt)
@property
- def allow_redirection(self) -> bool:
- """Read-only property to get whether or not redirection of stdout is allowed."""
- return self.statement_parser.allow_redirection
+ def aliases(self) -> bool:
+ """Read-only property to access the aliases stored in the StatementParser."""
+ return self.statement_parser.aliases
@property
def shortcuts(self) -> Tuple[Tuple[str, str]]:
"""Read-only property to access the shortcuts stored in the StatementParser."""
return self.statement_parser.shortcuts
+ @property
+ def allow_redirection(self) -> bool:
+ """Getter for the allow_redirection property that determines whether or not redirection of stdout is allowed."""
+ return self.statement_parser.allow_redirection
+
+ @allow_redirection.setter
+ def allow_redirection(self, value: bool) -> None:
+ """Setter for the allow_redirection property that determines whether or not redirection of stdout is allowed."""
+ self.statement_parser.allow_redirection = value
+
def decolorized_write(self, fileobj: IO, msg: str) -> None:
"""Write a string to a fileobject, stripping ANSI escape sequences if necessary