summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoris Roovers <joris.roovers@gmail.com>2019-08-15 09:31:41 +0200
committerJoris Roovers <joris.roovers@gmail.com>2019-08-15 09:31:41 +0200
commite6ae376a5a17e245d40c231478a840cd65ed422d (patch)
treec024d9f717db552cb4884b96b21e6d57f67aa79f
parentfe91fa91aca92e9ef6731c8ad63a87f4941c93f7 (diff)
Trying out dict optionsdict-option
-rw-r--r--.gitignore1
-rw-r--r--gitlint/config.py11
-rw-r--r--gitlint/options.py12
3 files changed, 23 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 938a64c..4f364ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover
+.pytest_cache/
# Translations
*.mo
diff --git a/gitlint/config.py b/gitlint/config.py
index 2d892bb..35938fe 100644
--- a/gitlint/config.py
+++ b/gitlint/config.py
@@ -255,9 +255,18 @@ class LintConfig(object):
def set_rule_option(self, rule_name_or_id, option_name, option_value):
""" Attempts to set a given value for a given option for a given rule.
LintConfigErrors will be raised if the rule or option don't exist or if the value is invalid. """
+ print option_name
+ option_name_parts = option_name.split(".")
+ option_name = option_name_parts[0]
+ print option_name
+ print option_value
+ print "---"
option = self._get_option(rule_name_or_id, option_name)
try:
- option.set(option_value)
+ if isinstance(option, options.DictOption):
+ option.set_key(".".join(option_name_parts[1:]), option_value)
+ else:
+ option.set(option_value)
except options.RuleOptionError as e:
msg = u"'{0}' is not a valid value for option '{1}.{2}'. {3}."
raise LintConfigError(msg.format(option_value, rule_name_or_id, option_name, ustr(e)))
diff --git a/gitlint/options.py b/gitlint/options.py
index d20549f..34664e8 100644
--- a/gitlint/options.py
+++ b/gitlint/options.py
@@ -44,6 +44,18 @@ class StrOption(RuleOption):
self.value = ustr(value)
+class DictOption(RuleOption):
+
+ def set(self, value):
+ if isinstance(value, dict):
+ self.value = value
+ else:
+ raise RuleOptionError(u"Option '{0}' must be python dict".format(self.name))
+
+ def set_key(self, key, value):
+ self.value[key].set(value)
+
+
class IntOption(RuleOption):
def __init__(self, name, value, description, allow_negative=False):
self.allow_negative = allow_negative