diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-02 15:30:16 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-10-02 15:30:16 -0400 |
commit | 1c0616a61740f1407f684a1dbe816fa547873b13 (patch) | |
tree | 36031a1b426bcbe7206233c765af1e813683c18d /cmd2/pyscript_bridge.py | |
parent | 4902d1c0c65c0804787e0a7174747df4ca416b8c (diff) | |
download | cmd2-git-1c0616a61740f1407f684a1dbe816fa547873b13.tar.gz |
Changed PyscriptBridge.__getattr__ to raise Attribute error for non-commands
Diffstat (limited to 'cmd2/pyscript_bridge.py')
-rw-r--r-- | cmd2/pyscript_bridge.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py index c8db0960..b66fd701 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/pyscript_bridge.py @@ -250,7 +250,10 @@ class PyscriptBridge(object): self.cmd_echo = False def __getattr__(self, item: str): - """If attribute is a command, return a callable. Otherwise return the attribute.""" + """ + Provide a way to call application commands via the PyscriptBridge + ex: app.help() + """ func = self._cmd2_app.cmd_func(item) if func: @@ -264,7 +267,8 @@ class PyscriptBridge(object): return wrap_func else: - return getattr(self._cmd2_app, item) + # item does not refer to a command + raise AttributeError("'{}' object has no attribute '{}'".format(self._cmd2_app.pyscript_name, item)) def __dir__(self): """Return a custom set of attribute names to match the available commands""" |