summaryrefslogtreecommitdiff
path: root/doc/adding-command.rst
diff options
context:
space:
mode:
authorVo Minh Thu <vmt@openerp.com>2013-01-11 14:46:57 +0100
committerVo Minh Thu <vmt@openerp.com>2013-01-11 14:46:57 +0100
commit3da57500c279cd19fa6d561eef149d708383138d (patch)
treee6ea46397217349ff0381b91346a1ba02394e14b /doc/adding-command.rst
parent3478333bca1a28483c1c7eb90431cb1e979c74ba (diff)
[ADD] oe: provides sane (unfucked) command-line interface.
The implementation is far from perfect. Some improvements are waiting in its previous location: lp:~openerp/openerp-command. Some docs are provided, see doc/openerp-command.rst and doc/adding-command.rst. bzr revid: vmt@openerp.com-20130111134657-im2f3uqjluyo4pm6
Diffstat (limited to 'doc/adding-command.rst')
-rw-r--r--doc/adding-command.rst34
1 files changed, 34 insertions, 0 deletions
diff --git a/doc/adding-command.rst b/doc/adding-command.rst
new file mode 100644
index 00000000000..5a177b06817
--- /dev/null
+++ b/doc/adding-command.rst
@@ -0,0 +1,34 @@
+.. _adding-command:
+
+Adding a new command
+====================
+
+``oe`` uses the argparse_ library to implement commands. Each
+command lives in its own ``openerpcommand/<command>.py`` file.
+
+.. _argparse: http://docs.python.org/2.7/library/argparse.html
+
+To create a new command, probably the most simple way to get started is to
+copy/paste an existing command, say ``openerpcommand/initialize.py`` to
+``openerpcommand/foo.py``. In the newly created file, the important bits
+are the ``run(args)`` and ``add_parser(subparsers)`` functions.
+
+``add_parser``'s responsability is to create a (sub-)parser for the command,
+i.e. describe the different options and flags. The last thing it does is to set
+``run`` as the function to call when the command is invoked.
+
+.. code-block:: python
+
+ > def add_parser(subparsers):
+ > parser = subparsers.add_parser('<command-name>',
+ > description='...')
+ > parser.add_argument(...)
+ > ...
+ > parser.set_defaults(run=run)
+
+``run(args)`` actually implements the command. It should be kept as simple as
+possible and delegate most of its work to small functions (probably placed at
+the top of the new file). In other words, its responsability is mainly to
+deal with the presence/absence/pre-processing of ``argparse``'s arguments.
+
+Finally, the module must be added to ``openerpcommand/__init__.py``.