aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-08-30 14:40:54 +0100
committerGravatar jesopo2019-08-30 14:40:54 +0100
commit4bfb4c3200506da63eb0451d42a300ee400a176c (patch)
treed3efea90a174ca39371938f6e552b26fc8f5c33a /src
parentLogging.BitBotFormatter no longer uses the format it's given (always iso8601) (diff)
signature
Add IntRangeSetting, reorder OptionsSetting arg order
Diffstat (limited to 'src')
-rw-r--r--src/utils/__init__.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index 69d74fa2..2202a3de 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -300,8 +300,25 @@ class IntSetting(Setting):
return int(stripped)
return None
+class IntRangeSetting(IntSetting):
+ example = None
+ def __init__(self, n_min: int, n_max: int, name: str, help: str=None,
+ example: str=None):
+ self._n_min = n_min
+ self._n_max = n_max
+ Setting.__init__(self, name, help, example)
+
+ def parse(self, value: str) -> typing.Any:
+ out = IntSetting.parse(self, value)
+ if not out == None and self._n_min <= out <= self._n_max:
+ return out
+ return None
+
+ def _format_example(self):
+ return "Must be between %d and %d" % (self._n_min, self._n_max)
+
class OptionsSetting(Setting):
- def __init__(self, name: str, options: typing.List[str], help: str=None,
+ def __init__(self, options: typing.List[str], name: str, help: str=None,
example: str=None,
options_factory: typing.Callable[[], typing.List[str]]=None):
self._options = options