~johanvdw/+junk/cligj

« back to all changes in this revision

Viewing changes to README.rst

  • Committer: Johan Van de Wauw
  • Date: 2015-08-19 21:04:38 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: johan.vandewauw@gmail.com-20150819210438-bfg3meh63395ox47
* Merge new version and ubuntu specific changes 

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
    ^^{'type': 'Feature', 'id': '2'}
61
61
 
62
62
In this example, ``^^`` represents 0x1e.
 
63
 
 
64
 
 
65
Plugins
 
66
-------
 
67
 
 
68
.. warning::
 
69
   The cligj.plugins module is deprecated and will be removed at version 1.0.
 
70
   Use `click-plugins <https://github.com/click-contrib/click-plugins>`_
 
71
   instead.
 
72
 
 
73
``cligj`` can also facilitate loading external `click-based
 
74
<http://click.pocoo.org/4/>`_ plugins via `setuptools entry points
 
75
<https://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins>`_.
 
76
The ``cligj.plugins`` module contains a special ``group()`` decorator that
 
77
behaves exactly like ``click.group()`` except that it offers the opportunity
 
78
load plugins and attach them to the group as it is istantiated.
 
79
 
 
80
.. code-block:: python
 
81
 
 
82
    from pkg_resources import iter_entry_points
 
83
 
 
84
    import cligj.plugins
 
85
    import click
 
86
 
 
87
    @cligj.plugins.group(plugins=iter_entry_points('module.entry_points'))
 
88
    def cli():
 
89
 
 
90
        """A CLI application."""
 
91
 
 
92
        pass
 
93
 
 
94
    @cli.command()
 
95
    @click.argument('arg')
 
96
    def printer(arg):
 
97
 
 
98
        """Print arg."""
 
99
 
 
100
        click.echo(arg)
 
101
 
 
102
    @cli.group(plugins=iter_entry_points('other_module.more_plugins'))
 
103
    def plugins():
 
104
 
 
105
        """A sub-group that contains plugins from a different module."""
 
106
        pass