1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-07 22:04:23 +00:00

monitor for bad option

This commit is contained in:
deadc0de6
2019-02-12 08:41:28 +01:00
parent 9462d8be23
commit ad2d74e0f1
4 changed files with 34 additions and 6 deletions

View File

@@ -67,7 +67,21 @@ Options:
""".format(BANNER, PROFILE)
class Options:
class AttrMonitor:
_set_attr_err = False
def __setattr__(self, key, value):
"""monitor attribute setting"""
if not hasattr(self, key) and self._set_attr_err:
self._attr_change(key)
super(AttrMonitor, self).__setattr__(key, value)
def _attr_set(self, attr):
"""do something when unexistent attr is set"""
pass
class Options(AttrMonitor):
def __init__(self, args=None):
"""constructor
@@ -89,6 +103,8 @@ class Options:
and not self.args['--no-banner']:
self._header()
self._print_attr()
# start monitoring for bad attribute
self._set_attr_err = True
def _header(self):
"""print the header"""
@@ -172,3 +188,7 @@ class Options:
if callable(val):
continue
self.log.dbg('- {}: \"{}\"'.format(att, val))
def _attr_set(self, attr):
"""error when some inexistent attr is set"""
raise Exception('bad option: {}'.format(attr))