Skip to content
Myr

Merge pull request #100 from julen/doc-fixes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Doc fixes

authored by Armin Ronacher · committed by Armin Ronacher · parents c13d723, 9ca2817 · Browse files · 4 files+13 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+13 added−13 removed

  • other:+13 added−13 removed

4 files+13 added−13 removed

modified:click/core.py+4 added-4 removed
26 unmodified lines
27 if args < 3:28 from warnings import warn29 warn(Warning('Invoked legacy parameter callback "%s". The new '30 'signature for such callbacks starting with '31 'Click 2.0 is (ctx, param, value).'31 'click 2.0 is (ctx, param, value).'32 % callback), stacklevel=3)33 return callback(ctx, value)34 return callback(ctx, param, value)35
259 unmodified lines
295 Most code will never use this as it does not implement a lot of useful296 functionality but it can act as the direct subclass of alternative297 parsing methods that do not depend on the click parser.298299 For instance this can be used to bridge Click and other systems like299 For instance this can be used to bridge click and other systems like300 argparse or docopt.301302 Because base commands do not implement a lot of the API that other303 parts of click take for granted they are not supported for all
456 unmodified lines
760 Some settings are supported by both options and arguments.761762 .. versionchanged:: 2.0763 Changed signature for parameter callback to also be passed the764 parameter. In Click 2.0 the old callback format will still work764 parameter. In click 2.0 the old callback format will still work765 but it will raise a warning to give you change to migrate the766 code easier.767768 :param param_decls: the parameter declarations for this option or
7 unmodified lines
776 in which case it's invoked when the default is needed777 without any arguments.778 :param callback: a callback that should be executed after the parameter779 was matched. This is called as ``fn(ctx, param,780 value)`` and needs to return the value. Before Click780 value)`` and needs to return the value. Before click781 2.0 the signature was ``(ctx, value)``.782 :param nargs: the number of arguments to match. If not ``1`` the return783 value is a tuple instead of single value.784 :param metavar: how the value is represented in the help page.
427 unmodified lines
modified:click/termui.py+1 added-1 removed
392 unmodified lines
393 :param env: environment variables to forward to the editor.394 :param require_save: if this is true, then not saving in the editor395 will make the return value become `None`.396 :param extension: the extension to tell the editor about. This defaults397 to utf-8 but changing this might change syntax397 to `.txt` but changing this might change syntax398 highlighting.399 :param filename: if provided it will edit this file instead of the400 provided text contents. It will not use a temporary401 file as an indirection in that case.
33 unmodified lines
modified:docs/options.rst+4 added-4 removed
325 unmodified lines
326 invoke(hello, args=['--version'])327328.. admonition:: Callback Signature Changes329330 In Click 2.0 the signature for callbacks changed. For more330 In click 2.0 the signature for callbacks changed. For more331 information about these changes see :ref:`upgrade-to-2.0`.332333Yes Parameters334--------------
34 unmodified lines
369 click.echo('Dropped all tables!')370371.. admonition:: Callback Signature Changes372373 In Click 2.0 the signature for callbacks changed. For more373 In click 2.0 the signature for callbacks changed. For more374 information about these changes see :ref:`upgrade-to-2.0`.375376Values from Environment Variables377---------------------------------
166 unmodified lines
544If you want to apply custom validation logic you can do this in the545parameter callbacks. These callbacks can both modify values as well as546raise errors if the validation does not work.547548In Click 1.0 you can only raise the :exc:`UsageError` but starting with549Click 2.0 you can also raie the :exc:`BadParameter` error which has the548In click 1.0 you can only raise the :exc:`UsageError` but starting with549click 2.0 you can also raie the :exc:`BadParameter` error which has the550added advantage that it will automatically format the error message to551also contain the parameter name.552553Example:
25 unmodified lines
modified:docs/upgrading.rst+4 added-4 removed
11 unmodified lines
12----------------1314Click 2.0 has one breaking change which is the signature for parameter15callbacks. Before 2.0 the callback was invoked with ``(ctx, value)``16wheras now it's ``(ctx, param, value)``. This change was necessary as it16whereas now it's ``(ctx, param, value)``. This change was necessary as it17otherwise made reusing callbacks too complicated.1819To ease the transition Click will still accept old callbacks but it will19To ease the transition click will still accept old callbacks but it will20issue a warning to stderr to encourage you to upgrade.2122In case you want to support both Click 1.0 and Click 2.0 you can make a22In case you want to support both click 1.0 and click 2.0 you can make a23simple decorator that adjusts the signatures::2425 import click26 from functools import update_wrapper
10 unmodified lines
37 @compatcallback38 def callback(ctx, param, value):39 return value.upper()4041Note that because Click 1.0 did not pass a parameter the `param` argument41Note that because click 1.0 did not pass a parameter the `param` argument42here would be `None` so a compatibility callback could not use that43argument.