Skip to content
Snippets Groups Projects
Verified Commit a9271b9c authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Add doctests to diagnostics

parent 01166917
Branches
Tags
No related merge requests found
...@@ -54,9 +54,44 @@ def get_files(): ...@@ -54,9 +54,44 @@ def get_files():
return result return result
def get_option(name, default=None): def get_option(name, default=None, args=None):
"""get_option
Return the value of a command line options by name or a default value if
the command line parameters do not contain such an option.
Examples
--------
>>> get_option("opt1", args=["--opt1=bla", "--opt2=blub"])
'bla'
>>> get_option("opt1", args=["--opt1", "bla", "--opt2", "blub"])
'bla'
>>> get_option("opt1", default="def", args=["--other=blub"])
'def'
>>> get_option("opt1", args=["--opt1", "--opt2=blub"])
True
>>> get_option("opt1", args=["--opt1"])
True
>>> get_option("opt1", args=["--other=blub"]) is None
True
Parameters
----------
name : str
The name
default : str (optional)
Return this value if the arguments do not contain the option. Defaults
to `None`.
args : list of str (optional)
List of command line parameters which are to be parsed. Defaults to
`sys.argv`.
Returns
-------
"""
_next = False _next = False
for arg in sys.argv: _args = args if args is not None else sys.argv
for arg in _args:
if _next is True: if _next is True:
if arg.startswith("--"): if arg.startswith("--"):
return True return True
...@@ -66,6 +101,8 @@ def get_option(name, default=None): ...@@ -66,6 +101,8 @@ def get_option(name, default=None):
return arg[index:] return arg[index:]
elif arg == "--{}".format(name): elif arg == "--{}".format(name):
_next = True _next = True
if _next is True:
return True
return default return default
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment