aboutsummaryrefslogtreecommitdiff
path: root/pw_cli/docs.rst
diff options
context:
space:
mode:
Diffstat (limited to 'pw_cli/docs.rst')
-rw-r--r--pw_cli/docs.rst73
1 files changed, 73 insertions, 0 deletions
diff --git a/pw_cli/docs.rst b/pw_cli/docs.rst
index 5d03f05b4..42144f1bd 100644
--- a/pw_cli/docs.rst
+++ b/pw_cli/docs.rst
@@ -265,3 +265,76 @@ Branding the ``pw`` tool is a great start, but more changes are planned:
- Supporting renaming the ``pw`` command to something project specific, like
``foo`` in this case.
- Re-coloring the log headers from the ``pw`` tool.
+
+pw_cli Python package
+=====================
+The ``pw_cli`` Pigweed module includes the ``pw_cli`` Python package, which
+provides utilities for creating command line tools with Pigweed.
+
+pw_cli.log
+----------
+.. automodule:: pw_cli.log
+ :members:
+
+pw_cli.plugins
+--------------
+:py:mod:`pw_cli.plugins` provides general purpose plugin functionality. The
+module can be used to create plugins for command line tools, interactive
+consoles, or anything else. Pigweed's ``pw`` command uses this module for its
+plugins.
+
+To use plugins, create a :py:class:`pw_cli.plugins.Registry`. The registry may
+have an optional validator function that checks plugins before they are
+registered (see :py:meth:`pw_cli.plugins.Registry.__init__`).
+
+Plugins may be registered in a few different ways.
+
+ * **Direct function call.** Register plugins by calling
+ :py:meth:`pw_cli.plugins.Registry.register` or
+ :py:meth:`pw_cli.plugins.Registry.register_by_name`.
+
+ .. code-block:: python
+
+ registry = pw_cli.plugins.Registry()
+
+ registry.register('plugin_name', my_plugin)
+ registry.register_by_name('plugin_name', 'module_name', 'function_name')
+
+ * **Decorator.** Register using the :py:meth:`pw_cli.plugins.Registry.plugin`
+ decorator.
+
+ .. code-block:: python
+
+ _REGISTRY = pw_cli.plugins.Registry()
+
+ # This function is registered as the "my_plugin" plugin.
+ @_REGISTRY.plugin
+ def my_plugin():
+ pass
+
+ # This function is registered as the "input" plugin.
+ @_REGISTRY.plugin(name='input')
+ def read_something():
+ pass
+
+ The decorator may be aliased to give a cleaner syntax (e.g. ``register =
+ my_registry.plugin``).
+
+ * **Plugins files.** Plugins files use a simple format:
+
+ .. code-block::
+
+ # Comments start with "#". Blank lines are ignored.
+ name_of_the_plugin module.name module_member
+
+ another_plugin some_module some_function
+
+ These files are placed in the file system and apply similarly to Git's
+ ``.gitignore`` files. From Python, these files are registered using
+ :py:meth:`pw_cli.plugins.Registry.register_file` and
+ :py:meth:`pw_cli.plugins.Registry.register_directory`.
+
+pw_cli.plugins module reference
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+.. automodule:: pw_cli.plugins
+ :members: