over.app.Main now uses a features dict instead of individual flags, closes #5
This commit is contained in:
parent
123b04c2b7
commit
720dfa7b09
2 changed files with 18 additions and 7 deletions
22
over/app.py
22
over/app.py
|
@ -162,6 +162,12 @@ def expand_group(token, options):
|
|||
# --------------------------------------------------
|
||||
|
||||
class Main:
|
||||
default_features = {
|
||||
"use_cfg_file": False,
|
||||
"auto_add_help": True,
|
||||
"handle_exceptions": True
|
||||
}
|
||||
|
||||
"""
|
||||
Application backbone. Provides:
|
||||
* A configuration system consisting of
|
||||
|
@ -172,7 +178,7 @@ class Main:
|
|||
* A prettyprinting exception handler.
|
||||
"""
|
||||
|
||||
def __init__(self, name, version=None, license=None, use_cfg_file=False, auto_add_help=True, handle_exceptions=True):
|
||||
def __init__(self, name, version=None, license=None, features={}):
|
||||
self.name = name
|
||||
self.version = version
|
||||
self.license = license
|
||||
|
@ -181,14 +187,20 @@ class Main:
|
|||
self.options_by_abbr = OrderedDict()
|
||||
self.cfg = ConfigRouter(self.options)
|
||||
self.targets = []
|
||||
self.auto_add_help = auto_add_help
|
||||
self.invocation = cmd.format_invocation(sys.argv)
|
||||
self.features = types.ndict()
|
||||
|
||||
if use_cfg_file:
|
||||
for feature_name in self.default_features:
|
||||
if feature_name in features:
|
||||
self.features[feature_name] = features[feature_name]
|
||||
else:
|
||||
self.features[feature_name] = self.default_features[feature_name]
|
||||
|
||||
if self.features.use_cfg_file:
|
||||
# TODO ensure it exists, update it with new values, etc.
|
||||
...
|
||||
|
||||
if handle_exceptions:
|
||||
if self.features.handle_exceptions:
|
||||
sys.excepthook = self.stack_tracer
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -278,7 +290,7 @@ class Main:
|
|||
cmdline = cmdline or sys.argv[1:]
|
||||
|
||||
# placing it here ensures --help is the last option in the list of options
|
||||
if self.auto_add_help:
|
||||
if self.features.auto_add_help:
|
||||
self.enable_help()
|
||||
|
||||
last_read_option = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue