docs: add some narrative docs to explain basic concepts

still needs a lot of work i'm sure..gotta start somewhere
This commit is contained in:
Lance Edgar 2024-12-07 18:14:11 -06:00
parent ba8f57ddc1
commit b3e4e91df8
11 changed files with 522 additions and 14 deletions

27
docs/narr/cli/builtin.rst Normal file
View file

@ -0,0 +1,27 @@
===================
Built-in Commands
===================
Below are the :term:`subcommands <subcommand>` which come with
WuttaSync.
It is fairly simple to add more; see :doc:`custom`.
.. _wutta-import-csv:
``wutta import-csv``
--------------------
Import data from CSV file(s) to the Wutta :term:`app database`.
This *should* be able to automatically target any table mapped in the
:term:`app model`. The only caveat is that it is "dumb" and does not
have any special field handling. This means the column headers in the
CSV file must be named the same as in the target table, and some data
types may not behave as expected etc.
Defined in: :mod:`wuttasync.cli.import_csv`
.. program-output:: wutta import-csv --help

64
docs/narr/cli/custom.rst Normal file
View file

@ -0,0 +1,64 @@
=================
Custom Commands
=================
This section describes how to add a custom :term:`subcommand` which
wraps a particular :term:`import handler`.
See also :doc:`wuttjamaican:narr/cli/custom` for more information
on the general concepts etc.
Basic Import/Export
-------------------
Here we'll assume you have a typical "Poser" app based on Wutta
Framework, and the "Foo → Poser" (``FromFooToPoser`` handler) import
logic is defined in the ``poser.importing.foo`` module.
We'll also assume you already have a ``poser`` top-level
:term:`command` (in ``poser.cli``), and our task now is to add the
``poser import-foo`` subcommand to wrap the import handler.
And finally we'll assume this is just a "typical" import handler and
we do not need any custom CLI params exposed.
Here is the code and we'll explain below::
from poser.cli import poser_typer
from wuttasync.cli import import_command, ImportCommandHandler
@poser_typer.command()
@import_command
def import_foo(ctx, **kwargs):
"""
Import data from Foo API to Poser DB
"""
config = ctx.parent.wutta_config
handler = ImportCommandHandler(
config, import_handler='poser.importing.foo:FromFooToPoser')
handler.run(ctx.params)
Hopefully it's straightforward but to be clear:
* subcommand is really just a function, **with desired name**
* wrap with ``@poser_typer.command()`` to register as subcomand
* wrap with ``@import_command`` to get typical CLI params
* call ``ImportCommandHandler.run()`` with import handler spec
So really - in addition to
:func:`~wuttasync.cli.base.import_command()` - the
:class:`~wuttasync.cli.base.ImportCommandHandler` is doing the heavy
lifting for all import/export subcommands, it just needs to know which
:term:`import handler` to use.
.. note::
If your new subcommand is defined in a different module than is the
top-level command (e.g. as in example above) then you may need to
"eagerly" import the subcommand module. (Otherwise auto-discovery
may not find it.)
This is usually done from within the top-level command's module,
since it is always imported early due to the entry point.

23
docs/narr/cli/index.rst Normal file
View file

@ -0,0 +1,23 @@
========================
Command Line Interface
========================
The primary way of using the import/export framework day to day is via
the command line.
WuttJamaican defines the ``wutta`` :term:`command` and WuttaSync comes
with some extra :term:`subcommands <subcommand>` for importing to /
exporting from the Wutta :term:`app database`.
It is fairly simple to add a dedicated subcommand for any
:term:`import handler`; see below.
And for more general info about CLI see
:doc:`wuttjamaican:narr/cli/index`.
.. toctree::
:maxdepth: 2
builtin
custom