diff --git a/uplaybook/__init__.py b/uplaybook/__init__.py index 461bde9..66bbb59 100644 --- a/uplaybook/__init__.py +++ b/uplaybook/__init__.py @@ -1,19 +1,20 @@ #!/usr/bin/env python3 """ -A Python-like declarative IT automation tool. +A Python-syntax declarative IT automation tool. uPlaybook2 takes ideas from Ansible and Cookiecutter and gives it a Python syntax rather than YAML. The desired state of the system is specified via this "playbook" and associated templates and data. You can then run this playbook, providing additional arguments for this run. -More documentation is available at: https://github.com/linsomniac/uplaybook2 +More documentation is available at: https://github.com/linsomniac/uplaybook """ from . import internals from . import fs from . import core +from . import pyinfra up_context = internals.up_context ARGS = up_context.context["ARGS"] diff --git a/uplaybook/cli.py b/uplaybook/cli.py index c633213..69d7db0 100644 --- a/uplaybook/cli.py +++ b/uplaybook/cli.py @@ -58,8 +58,25 @@ def find_updocs(name: str) -> str: """ if name == "__main__": from . import __doc__ - - return __doc__ + import uplaybook + import types + + modules_doc = "\nBuiltin Modules:\n\n" + module_list = [ + mod + for mod in [getattr(uplaybook, attr) for attr in dir(uplaybook)] + if isinstance(mod, types.ModuleType) + ] + for module in module_list: + if not hasattr(module, "__is_task_module__"): + continue + doc_firstline = module.__doc__.strip().split("\n")[0] + mod_name = module.__name__ + if mod_name.startswith("uplaybook."): + mod_name = mod_name.split(".", 1)[1] + modules_doc += f" {mod_name} - {doc_firstline}\n" + + return __doc__ + modules_doc # if a module is specified try: @@ -289,9 +306,6 @@ def parse_args() -> argparse.Namespace: remaining_args.insert(0, "--help") if args.docs_arg: display_docs(args.docs_arg) - if args.docs_arg == "__main__": - print() - parser.print_help() sys.exit(0) if not args.playbook: diff --git a/uplaybook/core.py b/uplaybook/core.py index d2c470d..d8dd449 100644 --- a/uplaybook/core.py +++ b/uplaybook/core.py @@ -6,6 +6,8 @@ Tasks that are a core part of uPlaybook. """ +__is_task_module__ = True + from .internals import ( Return, Exit, diff --git a/uplaybook/fs.py b/uplaybook/fs.py index 30314fa..fa6a83b 100644 --- a/uplaybook/fs.py +++ b/uplaybook/fs.py @@ -46,6 +46,8 @@ def semaphore_compose(): ## Tasks """ +__is_task_module__ = True + from .internals import ( Return, Failure, diff --git a/uplaybook/pyinfra/__init__.py b/uplaybook/pyinfra/__init__.py index 857ed4d..00302c5 100644 --- a/uplaybook/pyinfra/__init__.py +++ b/uplaybook/pyinfra/__init__.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 """ +A rich set of OS tasks + ## pyinfra Introduction uPlaybook wrappers of pyinfra https://docs.pyinfra.com/en/2.x/ operators. @@ -9,6 +11,8 @@ This wraps the pyinfra application. """ +__is_task_module__ = True + # Full docs are in `docs/tasks/pyinfra/intro.md` from collections import namedtuple