Skip to content
Myr

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

4 files+12 added−12 removed

modified:click/core.py+3 added-3 removed
316 unmodified lines
317 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.320321 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.323324 Because base commands do not implement a lot of the API that other325 parts of click take for granted they are not supported for all
466 unmodified lines
792 Some settings are supported by both options and arguments.793794 .. 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.799800 :param param_decls: the parameter declarations for this option or
7 unmodified lines
808 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 lines
modified:click/termui.py+1 added-1 removed
398 unmodified lines
399 :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 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.