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
Provenance
- Commit
76b4cf2- Tree
6c2f29b- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
c13d723- Parent 2
9ca2817
4 files changed+13 added−13 removed
modified:click/core.py+4 added-4 removed
26 unmodified lines27 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 lines295 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.298 299- 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.301 302 Because base commands do not implement a lot of the API that other303 parts of click take for granted they are not supported for all456 unmodified lines760 Some settings are supported by both options and arguments.761 762 .. 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.767 768 :param param_decls: the parameter declarations for this option or7 unmodified lines776 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 linesmodified:click/termui.py+1 added-1 removed
392 unmodified lines393 :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 linesmodified:docs/options.rst+4 added-4 removed
325 unmodified lines326 invoke(hello, args=['--version'])327 328 .. admonition:: Callback Signature Changes329 330- 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`.332 333 Yes Parameters334 --------------34 unmodified lines369 click.echo('Dropped all tables!')370 371 .. admonition:: Callback Signature Changes372 373- 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`.375 376 Values from Environment Variables377 ---------------------------------166 unmodified lines544 If you want to apply custom validation logic you can do this in the545 parameter callbacks. These callbacks can both modify values as well as546 raise errors if the validation does not work.547 548-In Click 1.0 you can only raise the :exc:`UsageError` but starting with549-Click 2.0 you can also raie the :exc:`BadParameter` error which has the548+In click 1.0 you can only raise the :exc:`UsageError` but starting with549+click 2.0 you can also raie the :exc:`BadParameter` error which has the550 added advantage that it will automatically format the error message to551 also contain the parameter name.552 553 Example:25 unmodified linesmodified:docs/upgrading.rst+4 added-4 removed
11 unmodified lines12 ----------------13 14 Click 2.0 has one breaking change which is the signature for parameter15 callbacks. Before 2.0 the callback was invoked with ``(ctx, value)``16-wheras now it's ``(ctx, param, value)``. This change was necessary as it16+whereas now it's ``(ctx, param, value)``. This change was necessary as it17 otherwise made reusing callbacks too complicated.18 19-To ease the transition Click will still accept old callbacks but it will19+To ease the transition click will still accept old callbacks but it will20 issue a warning to stderr to encourage you to upgrade.21 22-In case you want to support both Click 1.0 and Click 2.0 you can make a22+In case you want to support both click 1.0 and click 2.0 you can make a23 simple decorator that adjusts the signatures::24 25 import click26 from functools import update_wrapper10 unmodified lines37 @compatcallback38 def callback(ctx, param, value):39 return value.upper()40 41-Note that because Click 1.0 did not pass a parameter the `param` argument41+Note that because click 1.0 did not pass a parameter the `param` argument42 here would be `None` so a compatibility callback could not use that43 argument.