Skip to content

Commit

Permalink
--up-docs with no argument now prints a list of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
linsomniac committed Dec 22, 2023
1 parent e021eef commit 4d5994f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
5 changes: 3 additions & 2 deletions uplaybook/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
24 changes: 19 additions & 5 deletions uplaybook/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions uplaybook/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Tasks that are a core part of uPlaybook.
"""

__is_task_module__ = True

from .internals import (
Return,
Exit,
Expand Down
2 changes: 2 additions & 0 deletions uplaybook/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def semaphore_compose():
## Tasks
"""

__is_task_module__ = True

from .internals import (
Return,
Failure,
Expand Down
4 changes: 4 additions & 0 deletions uplaybook/pyinfra/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 4d5994f

Please sign in to comment.