Skip to content

Commit

Permalink
Adopt sphinx_click to auto-generate command refs in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Dec 21, 2023
1 parent 353c00b commit 8377308
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions aiomonitor/termui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
__all__ = (
"interact",
"monitor_cli",
"auto_command_done",
"auto_async_command_done",
"custom_help_option",
)


Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"sphinx_autodoc_typehints",
"sphinx_click",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ aiomonitor's documentation!
===========================

**aiomonitor** is Python 3.8+ module that adds monitor and cli capabilities
for asyncio_ application. Idea and code borrowed from curio_ project.
for :mod:`asyncio` application. Idea and code borrowed from curio_ project.
Task monitor that runs concurrently to the :mod:`asyncio` loop (or fast drop in
replacement uvloop_) in a separate thread. This can inspect the loop and
provide debugging capabilities.
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/termui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ Terminal UI

.. seealso:: Check out the tutorial :ref:`cust-commands` about adding custom commands.

.. _monitor-cli:

``aiomonitor.termui.commands``
------------------------------

.. automodule:: aiomonitor.termui.commands
:members:
:undoc-members:

.. click:: aiomonitor.termui.commands:monitor_cli
:prog: monitor_cli

``aiomonitor.termui.completion``
--------------------------------

Expand Down
14 changes: 12 additions & 2 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Once connection established, one can type commands, for instance ``help``::
where (w) Show stack frames and the task creation chain of a task
where-terminated (wt) Show stack frames and the termination/cancellation chain of a task

Additional commands can be added by defining a Click command function injected into :func:`aiomonitor.termui.commands.monitor_cli`, see below :ref:`cust-commands`.
Additional commands can be added by defining a Click command function injected into :ref:`the monitor CLI <monitor-cli>`, see below :ref:`cust-commands`.

.. versionchanged:: 0.5.0

Expand Down Expand Up @@ -150,12 +150,22 @@ As result variable ``foo`` available in console::
Adding custom commands
----------------------

By defining a new :func:`Click command <click.command>` on ``monitor_cli``, we can add our own commands to the
By defining a new :func:`Click command <click.command>` on :ref:`the monitor CLI <monitor-cli>`, we can add our own commands to the
telnet REPL. Use the standard :func:`click.echo()` to print something in the telnet console.
You may also add additional arguments and options just like a normal Click application.

.. code:: python
import aiohttp
import click
import requests
from aiomonitor.termui.commands import (
auto_async_command_done,
auto_command_done,
custom_help_option,
monitor_cli,
)
@monitor_cli.command(name="hello")
@click.argument("name", optional=True)
@custom_help_option
Expand Down

0 comments on commit 8377308

Please sign in to comment.