summaryrefslogtreecommitdiff
path: root/argparse_utils.py
diff options
context:
space:
mode:
authorScott <[email protected]>2022-01-26 21:34:26 -0800
committerScott <[email protected]>2022-01-26 21:34:26 -0800
commit36fea7f15ed17150691b5b3ead75450e575229ef (patch)
tree883ec076d7abe7683231244d27ca2c603ffcf031 /argparse_utils.py
parenta0c6b6c28214e0f5167bc25690ada5d83d933086 (diff)
Ran black code formatter on everything.
Diffstat (limited to 'argparse_utils.py')
-rw-r--r--argparse_utils.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/argparse_utils.py b/argparse_utils.py
index 1c61b24..8c254ae 100644
--- a/argparse_utils.py
+++ b/argparse_utils.py
@@ -17,12 +17,7 @@ logger = logging.getLogger(__name__)
class ActionNoYes(argparse.Action):
def __init__(
- self,
- option_strings,
- dest,
- default=None,
- required=False,
- help=None
+ self, option_strings, dest, default=None, required=False, help=None
):
if default is None:
msg = 'You must provide a default with Yes/No action'
@@ -47,14 +42,13 @@ class ActionNoYes(argparse.Action):
const=None,
default=default,
required=required,
- help=help
+ help=help,
)
@overrides
def __call__(self, parser, namespace, values, option_strings=None):
- if (
- option_strings.startswith('--no-') or
- option_strings.startswith('--no_')
+ if option_strings.startswith('--no-') or option_strings.startswith(
+ '--no_'
):
setattr(namespace, self.dest, False)
else:
@@ -89,6 +83,7 @@ def valid_bool(v: Any) -> bool:
if isinstance(v, bool):
return v
from string_utils import to_bool
+
try:
return to_bool(v)
except Exception:
@@ -110,6 +105,7 @@ def valid_ip(ip: str) -> str:
"""
from string_utils import extract_ip_v4
+
s = extract_ip_v4(ip.strip())
if s is not None:
return s
@@ -136,6 +132,7 @@ def valid_mac(mac: str) -> str:
"""
from string_utils import extract_mac_address
+
s = extract_mac_address(mac)
if s is not None:
return s
@@ -206,6 +203,7 @@ def valid_date(txt: str) -> datetime.date:
-ANYTHING-
"""
from string_utils import to_date
+
date = to_date(txt)
if date is not None:
return date
@@ -228,6 +226,7 @@ def valid_datetime(txt: str) -> datetime.datetime:
-ANYTHING-
"""
from string_utils import to_datetime
+
dt = to_datetime(txt)
if dt is not None:
return dt
@@ -250,6 +249,7 @@ def valid_duration(txt: str) -> datetime.timedelta:
"""
from datetime_utils import parse_duration
+
try:
secs = parse_duration(txt)
except Exception as e:
@@ -260,5 +260,6 @@ def valid_duration(txt: str) -> datetime.timedelta:
if __name__ == '__main__':
import doctest
+
doctest.ELLIPSIS_MARKER = '-ANYTHING-'
doctest.testmod()