Skip to content

Commit 3a81c26

Browse files
author
Omer Katz
committed
Update documentation on changes to custom CLI options in 5.0.
Fixes celery#6380.
1 parent 208e90e commit 3a81c26

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
extra_intersphinx_mapping={
2525
'cyanide': ('https://cyanide.readthedocs.io/en/latest', None),
26+
'click': ('https://click.palletsprojects.com/en/7.x/', None),
2627
},
2728
apicheck_ignore_modules=[
2829
'celery.__main__',

docs/userguide/extending.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -729,25 +729,22 @@ You can add additional command-line options to the ``worker``, ``beat``, and
729729
``events`` commands by modifying the :attr:`~@user_options` attribute of the
730730
application instance.
731731

732-
Celery commands uses the :mod:`argparse` module to parse command-line
733-
arguments, and so to add custom arguments you need to specify a callback
734-
that takes a :class:`argparse.ArgumentParser` instance - and adds arguments.
735-
Please see the :mod:`argparse` documentation to read about the fields supported.
732+
Celery commands uses the :mod:`click` module to parse command-line
733+
arguments, and so to add custom arguments you need to add :class:`click.Option` instances
734+
to the relevant set.
736735

737736
Example adding a custom option to the :program:`celery worker` command:
738737

739738
.. code-block:: python
740739
741740
from celery import Celery
741+
from click import Option
742742
743743
app = Celery(broker='amqp://')
744744
745-
def add_worker_arguments(parser):
746-
parser.add_argument(
747-
'--enable-my-option', action='store_true', default=False,
748-
help='Enable custom option.',
749-
),
750-
app.user_options['worker'].add(add_worker_arguments)
745+
app.user_options['worker'].add(Option(('--enable-my-option',),
746+
is_flag=True,
747+
help='Enable custom option.'))
751748
752749
753750
All bootsteps will now receive this argument as a keyword argument to

docs/whatsnew-5.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ As a result a few breaking changes has been introduced:
275275
- :program:`celery amqp` and :program:`celery shell` require the `repl`
276276
sub command to start a shell. You can now also invoke specific commands
277277
without a shell. Type `celery amqp --help` or `celery shell --help` for details.
278+
- The API for adding user options has changed.
279+
Refer to the :ref:`documentation <extending-command-options>` for details.
278280

279281
Click provides shell completion `out of the box <https://click.palletsprojects.com/en/7.x/bashcomplete/>`_.
280282
This functionality replaces our previous bash completion script and adds

0 commit comments

Comments
 (0)