moved the doc generation to an recursive function
Dieser Commit ist enthalten in:
Ursprung
d2375e07a6
Commit
f2f3580337
|
@ -9,15 +9,43 @@ try:
|
|||
except ImportError:
|
||||
from plugins.module_utils.generic import Types, _sdict
|
||||
|
||||
|
||||
__all__ = (
|
||||
"AnsibleModule",
|
||||
"SystemdUnitModule",
|
||||
"installable",
|
||||
"SystemdReloadMixin",
|
||||
)
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def docify(input: Union[dict, _sdict]) -> dict:
|
||||
options = dict()
|
||||
for name, help in input.items():
|
||||
options[name] = dict(type=help["type"])
|
||||
if hasattr(help, "_help") and help._help is not None:
|
||||
options[name]["description"] = help._help
|
||||
if "description" in help and isinstance(help["description"], str):
|
||||
options[name]["description"] = options[name]["description"].split("\n")
|
||||
if "required" in help and help["required"]:
|
||||
options[name]["required"] = True
|
||||
else:
|
||||
options[name]["required"] = False
|
||||
if help["type"] == "list":
|
||||
options[name]["elements"] = help["elements"]
|
||||
if not options[name]["required"]:
|
||||
options[name]["default"] = []
|
||||
if "default" in help:
|
||||
options[name]["default"] = help["default"]
|
||||
if "options" in help:
|
||||
options[name]["options"] = docify(help["options"])
|
||||
if "choices" in help:
|
||||
options[name]["choices"] = tuple(help["choices"])
|
||||
return options
|
||||
|
||||
|
||||
class AnsibleModule(object):
|
||||
"""Simple wrapper for the basic.AnsibleModule"""
|
||||
|
||||
|
@ -149,31 +177,13 @@ class AnsibleModule(object):
|
|||
doc = cls.__doc__
|
||||
if doc is None:
|
||||
doc = ""
|
||||
options = dict()
|
||||
help: _sdict
|
||||
specs = dict()
|
||||
if "argument_spec" in cls._common_args:
|
||||
specs.update(cls._common_args["argument_spec"])
|
||||
if "argument_spec" in cls.module_spec:
|
||||
specs.update(cls.module_spec["argument_spec"])
|
||||
for option, help in specs.items():
|
||||
options[option] = dict(
|
||||
type=help["type"],
|
||||
)
|
||||
if hasattr(help, "_help") and help._help is not None:
|
||||
options[option]["description"] = help._help.split("\n")
|
||||
if "required" in help and help["required"]:
|
||||
options[option]["required"] = True
|
||||
else:
|
||||
options[option]["required"] = False
|
||||
if help["type"] == "list":
|
||||
options[option]["elements"] = help["elements"]
|
||||
if not options[option]["required"]:
|
||||
options[option]["default"] = []
|
||||
if "default" in help:
|
||||
options[option]["default"] = help["default"]
|
||||
if "choices" in help:
|
||||
options[option]["choices"] = tuple(help["choices"])
|
||||
options = docify(specs)
|
||||
docu = doc.split("\n")
|
||||
return str(
|
||||
yaml.safe_dump(
|
||||
|
|
Laden…
In neuem Issue referenzieren