U a: @sddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZejd ejdejfdZedejdejfe ZeedddZeedddZd;ejeddddZddeejeddddZeejeej eejfeje e dd d!Z!ddddd5ejeeejeejeejeejejegefd6d7d8Z)eejejegefd0d9d:Z*dS)?N)update_wrapper)gettext)Argument)Command)Context)Group)Option) Parameterget_current_context)echoF.)boundFCfreturncsfdd}ttt|S)z]Marks a callback as wanting to receive the current context object as first argument. cstf||SNr argskwargsrQC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-s9fh6ldx\click\decorators.pynew_funcszpass_context..new_funcrtcastrrrrrr pass_contexts r csfdd}ttt|S)zSimilar to :func:`pass_context`, but only pass the object on the context onwards (:attr:`Context.obj`). This is useful if that object represents the state of a nested system. cstjf||Sr)r objrrrrr%szpass_obj..new_funcrrrrrpass_objs r"Fzt.Callable[[F], F]) object_typeensurercsttdfdd }|S)a.Given an object type this creates a decorator that will work similar to :func:`pass_obj` but instead of passing the object of the current context, it will find the innermost context of type :func:`object_type`. This generates a decorator that works roughly like this:: from functools import update_wrapper def decorator(f): @pass_context def new_func(ctx, *args, **kwargs): obj = ctx.find_object(object_type) return ctx.invoke(f, obj, *args, **kwargs) return update_wrapper(new_func, f) return decorator :param object_type: the type of the object to pass. :param ensure: if set to `True`, a new object will be created and remembered on the context if it's not there yet. rcs"fdd}ttt|S)NcsNt}r|}n |}|dkr:tdjd|j|f||S)Nz.decorator..new_funcrrr$r#rr decoratorDsz&make_pass_decorator..decorator)r)r#r$r+rr*rmake_pass_decorator+sr,)doc_description)keyr-rcs:ttdfdd }|dkr(dd}d|d|_|S) a{Create a decorator that passes a key from :attr:`click.Context.meta` as the first argument to the decorated function. :param key: Key in ``Context.meta`` to pass. :param doc_description: Description of the object being passed, inserted into the decorator's docstring. Defaults to "the 'key' key from Context.meta". .. versionadded:: 8.0 rcs fdd}ttt|S)Ncs$t}|j}|j|f||Sr)r metar'r()rr.rrrks z2pass_meta_key..decorator..new_funcrrr.rrr+jsz pass_meta_key..decoratorNzthe z$ key from :attr:`click.Context.meta`zDecorator that passes z1 as the first argument to the decorated function.)r__doc__)r.r-r+rr0r pass_meta_key[s   r2)rnameattrsclsrcCst|trtdz|j}||`Wntk r@g}YnX|d}|dkr`t|}n t |}||d<|f|p|j dd||d|S)Nz5Attempted to convert a callback into a command twice.help_-)r3callbackparams) isinstancer TypeError__click_params__reverseAttributeErrorgetinspectgetdoccleandocr&lowerreplace)rr3r4r5r:r6rrr _make_command|s(     rF)r3r5r4rc s4dkr ttjdtjftdfdd }|S)arCreates a new :class:`Command` and uses the decorated function as callback. This will also automatically attach all decorated :func:`option`\s and :func:`argument`\s as parameters to the command. The name of the command defaults to the name of the function with underscores replaced by dashes. If you want to change that, you can pass the intended name as the first argument. All keyword arguments are forwarded to the underlying command class. Once decorated the function turns into a :class:`Command` instance that can be invoked as a command line utility or be attached to a command :class:`Group`. :param name: the name of the command. This defaults to the function name with underscores replaced by dashes. :param cls: the command class to instantiate. This defaults to :class:`Command`. N.rcst|}|j|_|Sr)rFr1)rcmdr4r5r3rrr+szcommand..decorator)rrCallableAny)r3r5r4r+rrHrcommands$rK)r3r4rcKs |dtttt|f|S)zCreates a new :class:`Group` with a function as callback. This works otherwise the same as :func:`command` just that the `cls` parameter is set to :class:`Group`. r5) setdefaultrrrrK)r3r4rrrgroups rM)rparamrcCs8t|tr|j|nt|ds(g|_|j|dS)Nr=)r;rr:appendhasattrr=)rrNrrr _param_memos   rQ) param_declsr4rcsttdfdd }|S)aAttaches an argument to the command. All positional arguments are passed as parameter declarations to :class:`Argument`; all keyword arguments are forwarded unchanged (except ``cls``). This is equivalent to creating an :class:`Argument` instance manually and attaching it to the :attr:`Command.params` list. :param cls: the argument class to instantiate. This defaults to :class:`Argument`. rcs"dt}t||f|S)Nr5)poprrQ)rZ ArgumentClassr4rRrrr+s zargument..decoratorrrRr4r+rrTrarguments rWcsttdfdd }|S)aAttaches an option to the command. All positional arguments are passed as parameter declarations to :class:`Option`; all keyword arguments are forwarded unchanged (except ``cls``). This is equivalent to creating an :class:`Option` instance manually and attaching it to the :attr:`Command.params` list. :param cls: the option class to instantiate. This defaults to :class:`Option`. rcsD}d|kr"t|d|d<|dt}t||f||S)Nr6r5)copyrArCrSr rQ)rZ option_attrsZ OptionClassrTrrr+s  zoption..decoratorrUrVrrTroptions  rY)rRrrcOsbtttdddd}|sd}|dd|d||d d |d d |d dt||S)a-Add a ``--yes`` option which shows a prompt before continuing if not passed. If the prompt is declined, the program will exit. :param param_decls: One or more option names. Defaults to the single value ``"--yes"``. :param kwargs: Extra arguments are passed to :func:`option`. Nr)rNvaluercSs|s |dSr)abortr)rNr[rrrr9sz%confirmation_option..callback)z--yesis_flagTr9 expose_valueFpromptzDo you want to continue?r6z%Confirm the action without prompting.)rr boolrLrYrRrr9rrrconfirmation_options      rccOs6|sd}|dd|dd|ddt||S)a0Add a ``--password`` option which prompts for a password, hiding input and asking to enter the value again for confirmation. :param param_decls: One or more option names. Defaults to the single value ``"--password"``. :param kwargs: Extra arguments are passed to :func:`option`. )z --passwordr`TZconfirmation_promptZ hide_input)rLrY)rRrrrrpassword_options    rd) package_name prog_namemessage)versionrRrerfrgrrc sdkrtddkrdkrt}|dk s4t|jdk sBt|dk rR|jjnd}~|dk r|ddkr||drddtt t ddfd d }|sd }| d d | dd| dd | dtd||d<t ||S)aAdd a ``--version`` option which immediately prints the version number and exits the program. If ``version`` is not provided, Click will try to detect it using :func:`importlib.metadata.version` to get the version for the ``package_name``. On Python < 3.8, the ``importlib_metadata`` backport must be installed. If ``package_name`` is not provided, Click will try to detect it by inspecting the stack frames. This will be used to detect the version, so it must match the name of the installed package. :param version: The version number to show. If not provided, Click will try to detect it. :param param_decls: One or more option names. Defaults to the single value ``"--version"``. :param package_name: The package name to detect the version from. If not provided, Click will try to detect it. :param prog_name: The name of the CLI to show in the message. If not provided, it will be detected from the command. :param message: The message to show. The values ``%(prog)s``, ``%(package)s``, and ``%(version)s`` are available. Defaults to ``"%(prog)s, version %(version)s"``. :param kwargs: Extra arguments are passed to :func:`option`. :raise RuntimeError: ``version`` could not be detected. .. versionchanged:: 8.0 Add the ``package_name`` parameter, and the ``%(package)s`` value for messages. .. versionchanged:: 8.0 Use :mod:`importlib.metadata` instead of ``pkg_resources``. The version is detected based on the package name, not the entry point name. The Python package name must match the installed package name, or be passed with ``package_name=``. Nz%(prog)s, version %(version)sr&__main__ __package__.rrZcs|r |jrdSdkr |jdkrdk rzddlm}Wntk r\ddl}YnXz|Wn$|jk rt dYnXdkrt ddt t t d|jd|dS)Nr)metadataz6 is not installed. Try passing 'package_name' instead.z$Could not determine the version for z automatically.)progpackagerhcolor)resilient_parsingZ find_rootZ info_name importlibrl ImportErrorZimportlib_metadatarhZPackageNotFoundErrorr%r rrstrrpexit)r)rNr[rlrgrerfrhrrr9gs4      z version_option..callback)z --versionr^Tr_Fis_eagerr6zShow the version and exit.r9) r7rA currentframeAssertionErrorf_back f_globalsr@ partitionrr rarLrY) rhrerfrgrRrframer{r9rrvrversion_option&s.,   '   r~cOsbtttdddd}|sd}|dd|dd |d d|d td ||d <t||S)aAdd a ``--help`` option which immediately prints the help page and exits the program. This is usually unnecessary, as the ``--help`` option is added to each command automatically unless ``add_help_option=False`` is passed. :param param_decls: One or more option names. Defaults to the single value ``"--help"``. :param kwargs: Extra arguments are passed to :func:`option`. NrZcSs,|r |jrdSt||jd|dS)Nro)rqr Zget_helprprur]rrrr9s zhelp_option..callback)z--helpr^Tr_Frwr6zShow this message and exit.r9)rr rarLr7rYrbrrr help_options    r)F)NN)N)N)+rAtypestypingr functoolsrrr7corerrrrr r globalsr utilsr TypeVarrIrJrrr r"Typerar,rtOptionalr2MutableMappingrFrKrMrQrWrYrcrdr~rrrrrs~             1 " ! #(      s