a =jgI @sddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZejrddlZed ZedZedZejdejfZejdejee fdZdddddZ dddddZ!dKej"ee#ejdgdfdddZ$dd e%ej&e%d!d"d#d$Z'ejd%e dZ(ej)ee d&d'd(Z*ej)ej&e%ej"e(ejejege(fd)d*d(Z*ej)dLdej"e(ejejege(fd)d+d(Z*ej)dMej&e%dejejege fd)d,d(Z*dNejej&e%efej&ej"e(ejeje ejegeje e(fffd)d-d(Z*ejd.e dZ+ej)ee d&d/d0Z,ej)ej&e%ej"e+ejejege+fd)d1d0Z,ej)dOdej"e+ejejege+fd)d2d0Z,ej)dPej&e%dejejege fd)d3d0Z,dQeje%edfej&ej"e+ejeje ejegeje e+fffd)d4d0Z,ejdejfedd5d6d7Z-dd8e%ej&ej"e ejejegefd9d:d;Z.dd8e%ej&ej"e ejejegefd9dd?d@Z0e%ejejegefd>dAdBZ1dRddddCej&e%e%ej&e%ej&e%ej&e%ejejegefdDdEdFZ2GdGdHdHe Z3e%ejejegefd>dIdJZ4dS)SNupdate_wrapper)gettext)Argument)Command)Context)Group)Option) Parameterget_current_context)echoPRT.FC)boundz)t.Callable[te.Concatenate[Context, P], R]t.Callable[P, R]freturncs ddddfdd }t|S)z]Marks a callback as wanting to receive the current context object as first argument. P.argsP.kwargsrargskwargsrcstg|Ri|SNr rrr:/usr/local/lib/python3.9/site-packages/click/decorators.pynew_func szpass_context..new_funcrrr"r rr! pass_contextsr$'t.Callable[te.Concatenate[t.Any, P], R]cs ddddfdd }t|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. rrrrcstjg|Ri|Sr)r objrrr r!r",szpass_obj..new_funcrr#r rr!pass_obj&sr'F#t.Callable[te.Concatenate[T, P], R]) object_typeensurercsdddfdd }|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. r(rrcs$ddddfdd }t|S)NrrrrcsTt}r|}n |}|dur:tdjd|j|g|Ri|S)Nz.decorator..new_funcrr#r*r)rr! decoratorKsz&make_pass_decorator..decoratorr )r)r*r1r r0r!make_pass_decorator2sr2)doc_descriptionzGt.Callable[[t.Callable[te.Concatenate[t.Any, P], R]], t.Callable[P, R]])keyr3rcs:dddfdd }|dur(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 r%rrcs"ddtdfdd }t|S)Nrrrcs*t}|j}|j|g|Ri|Sr)r metar-r.)rr4r r!r"ss z2pass_meta_key..decorator..new_func)rrr#r4rr!r1rsz pass_meta_key..decoratorNzthe z$ key from :attr:`click.Context.meta`zDecorator that passes z1 as the first argument to the decorated function.)__doc__)r4r3r1r r6r! pass_meta_keycs   r8CmdType)namercCsdSrr r:r r r!commandsr<)r:clsattrsrcKsdSrr r:r=r>r r r!r<scKsdSrr r?r r r!r<scKsdSrr r?r r r!r<sc svd}tr0}ddus$Jdr0JddurJttjttttdfdd }|durr||S|S)aCreates 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. For the ``params`` argument, any decorated params are appended to the end of the list. 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`. .. versionchanged:: 8.1 This decorator can be applied without parentheses. .. versionchanged:: 8.1 The ``params`` argument can be used. Decorated params are appended to the end of the list. Nz4Use 'command(cls=cls)(callable)' to specify a class.z7Use 'command(**kwargs)(callable)' to provide arguments.rcst|trtddd}|dur*|ng}z |j}WntyJYn0|`|t|ddurv|j d<t j rdusJt rJfp|j dd||d}|j |_ |S)Nz5Attempted to convert a callback into a command twice.paramshelp_-)r:callbackr@) isinstancer TypeErrorpop__click_params__AttributeErrorextendreversedgetr7t TYPE_CHECKINGcallabler,lowerreplace)rZ attr_paramsr@Zdecorator_paramscmdr>r=r:r r!r1s0       zcommand..decorator)rOrMcastTyper9r _AnyCallable)r:r=r>funcr1r rSr!r<s" GrpTypecCsdSrr r;r r r!groupsrYcKsdSrr r?r r r!rYscKsdSrr r?r r r!rY scKsdSrr r?r r r!rYscKsJ|durttjtt}t|r8tfd|i||St||fi|S)aCreates 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`. .. versionchanged:: 8.1 This decorator can be applied without parentheses. Nr=)rMrTrUrXr rOr<r?r r r!rYs )rparamrcCs8t|tr|j|nt|ds(g|_|j|dS)NrH)rErr@appendhasattrrH)rrZr r r! _param_memo1s   r])r=) param_declsr=r>rcs(dur tttdfdd }|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. For the default argument class, refer to :class:`Argument` and :class:`Parameter` for descriptions of parameters. :param cls: the argument class to instantiate. This defaults to :class:`Argument`. :param param_decls: Passed as positional arguments to the constructor of ``cls``. :param attrs: Passed as keyword arguments to the constructor of ``cls``. Nrcst|fi|Srr]rr>r=r^r r!r1Pszargument..decorator)rrr=r^r>r1r r`r!argument;srbcs(dur tttdfdd }|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. For the default option class, refer to :class:`Option` and :class:`Parameter` for descriptions of parameters. :param cls: the option class to instantiate. This defaults to :class:`Option`. :param param_decls: Passed as positional arguments to the constructor of ``cls``. :param attrs: Passed as keyword arguments to the constructor of ``cls``. Nrcst|fi|Srr_rr`r r!r1lszoption..decorator)r rrar r`r!optionWsrcr^rrcOsftttdddd}|sd}|dd|d||d d |d d |d dt|i|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/rZvaluercSs|s |dSr)abortr/rZrfr r r!rD|sz%confirmation_option..callback)z--yesis_flagTrD expose_valueFpromptzDo you want to continue?rAz%Confirm the action without prompting.)rr bool setdefaultrc)r^rrDr r r!confirmation_optionss      rncOs:|sd}|dd|dd|ddt|i|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 --passwordrkTZconfirmation_promptZ hide_input)rmrcr^rr r r!password_options    rp) package_name prog_namemessage)versionr^rqrrrsrrc sdurtddurdurt}|dur6|jnd}|durH|jnd}~|dur|ddkrr|drddttt ddfd d } |sd }| d d | dd| dd | dtd| |d<t |i|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__.rrecs|r |jrdSdur |jdurdurzddlm}WntyZddl}Yn0z|Wn$|jyt ddYn0durt ddt d|j d| dS)Nr)metadataz6 is not installed. Try passing 'package_name' instead.z$Could not determine the version for z automatically.)progpackagertcolor) resilient_parsingZ find_rootZ info_name importlibrx ImportErrorZimportlib_metadatartPackageNotFoundErrorr+rr|exit)r/rZrfrxrsrqrrrtr r!rDs4    z version_option..callback)z --versionriTrjFis_eagerrAzShow the version and exit.rD) rBinspect currentframef_back f_globalsrL partitionrr rlrmrc) rtrqrrrsr^rframerrrDr rr!version_options,,  &   rcsReZdZdZd ejejeejddfdd Z e e e e ddddZZS) HelpOptionzgPre-configured ``--help`` option which immediately prints the help page and exits the program. Nrdc sb|sd}|dd|dd|dd|dtd|d |jtj|fi|dS) N)z--helpriTrjFrrAzShow this message and exit.rD)rmrB show_helpsuper__init__)selfr^r __class__r r!rs   zHelpOption.__init__recCs(|r$|js$t||jd|dS)z`` and exits.r{N)r}rZget_helpr|rrhr r r!r"s zHelpOption.show_help)N)r, __module__ __qualname__r7rMOptionalSequencestrAnyr staticmethodrr rlr __classcell__r r rr!r srcOs|dtt|i|S)zDecorator for the pre-configured ``--help`` option defined above. :param param_decls: One or more option names. Defaults to the single value ``"--help"``. :param kwargs: Extra arguments are passed to :func:`option`. r=)rmrrcror r r! help_option*s r)F)N).N)NN)N).N)NN)N)5rtypestypingrM functoolsrrrBcorerrrr r r globalsr utilsrrNtyping_extensionste ParamSpecrTypeVarrrCallablerrVUnionrr$r'rUrlr2rrr8r9overloadr<rXrYr]rbrcrnrprrrr r r r!s                 2  ! " R "       q