Merge branch 'master' of https://github.com/mitsuhiko/click
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parents 236e09c, 76b4cf2 · Browse files · 4 files·+12 added−12 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+12 added−12 removed
- other:+12 added−12 removed
Provenance
- Commit
8bd9f7a- Tree
3998575- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
236e09c- Parent 2
76b4cf2
4 files changed+12 added−12 removed
modified:click/core.py+3 added-3 removed
316 unmodified lines317 Most code will never use this as it does not implement a lot of useful318 functionality but it can act as the direct subclass of alternative319 parsing methods that do not depend on the click parser.320 321- For instance this can be used to bridge Click and other systems like321+ For instance this can be used to bridge click and other systems like322 argparse or docopt.323 324 Because base commands do not implement a lot of the API that other325 parts of click take for granted they are not supported for all466 unmodified lines792 Some settings are supported by both options and arguments.793 794 .. versionchanged:: 2.0795 Changed signature for parameter callback to also be passed the796- parameter. In Click 2.0 the old callback format will still work796+ parameter. In click 2.0 the old callback format will still work797 but it will raise a warning to give you change to migrate the798 code easier.799 800 :param param_decls: the parameter declarations for this option or7 unmodified lines808 in which case it's invoked when the default is needed809 without any arguments.810 :param callback: a callback that should be executed after the parameter811 was matched. This is called as ``fn(ctx, param,812- value)`` and needs to return the value. Before Click812+ value)`` and needs to return the value. Before click813 2.0 the signature was ``(ctx, value)``.814 :param nargs: the number of arguments to match. If not ``1`` the return815 value is a tuple instead of single value.816 :param metavar: how the value is represented in the help page.437 unmodified linesmodified:click/termui.py+1 added-1 removed
398 unmodified lines399 :param env: environment variables to forward to the editor.400 :param require_save: if this is true, then not saving in the editor401 will make the return value become `None`.402 :param extension: the extension to tell the editor about. This defaults403- to utf-8 but changing this might change syntax403+ to `.txt` but changing this might change syntax404 highlighting.405 :param filename: if provided it will edit this file instead of the406 provided text contents. It will not use a temporary407 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.