a =jg<@sTddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZd d lmZd d lmZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dl m!Z!d dl m"Z"d dl#m$Z$d dl#m%Z%d dl#m&Z&d dl'm(Z(d dl'm)Z)d dl'm*Z*d dl+m,Z,d dl+m-Z-d dl+m.Z.d dl+m/Z/d d l+m0Z0d d!l+m1Z1ej2rddl3Z4d d"l5m6Z6d d#l7m8Z8ej9d$ej:d%ej;fd&Zej?ej@e>d)fd*d+d,ZAdOd.e>d)eBdd/d0d1ZCejDe=eEejFej@e=d%fd2d3d4ZGe dPd(ejHd5ej?dd6d7d8ZIejJd5ejJd5ejFd5d9d:d;ZKGdd(d(ZNGd?d@d@ZOGdAd)d)eOZPGdBd.d.ePZQGdCdDdDeQZRGdEdFdFeQZSej;ej?ej;dGdHdIZTGdJd5d5ZUGdKdLdLeUZVGdMdNdNeUZWdS)QN)abc)contextmanager) ExitStack)update_wrapper)gettext)ngettext)repeat) TracebackType)typesAbort) BadParameter)ClickExceptionExit)MissingParameter UsageError) HelpFormatter) join_options) pop_context) push_context_flag_needs_value) OptionParser) split_opt)confirm)prompt)style)_detect_program_name) _expand_args)echo)make_default_short_help)make_str)PacifyFlushWrapper HelpOptionCompletionItemF.)boundVContextCommandctx incompletereturnccsPtt|j}||D]2}||r|||}|dur|js||fVqdS)zList all the subcommands of a group that start with the incomplete value and aren't hidden. :param ctx: Invocation context for the group. :param incomplete: Value being completed. May be empty. N)tcast MultiCommandcommand list_commands startswith get_commandhidden)r0r1multinamer6r=4/usr/local/lib/python3.9/site-packages/click/core.py_complete_visible_commands2s   r?Fr5) base_commandcmd_namecmdregisterr2cCsh|jrt|tsdS|rd}nd}t|d|jd|d|dt|jdt|jd|jd dS) NzdIt is not possible to add multi commands as children to another multi command that is in chain mode.zdFound a multi command as subcommand to a multi command that is in chain mode. This is not supported.z . Command z is set to chain and zA was added as a subcommand but it in itself is a multi command. (z is a z within a chained z named z).)chain isinstancer5 RuntimeErrorr<type__name__)r@rArBrChintr=r=r>_check_multicommandEs(rJ)iterable batch_sizer2cCstttt||SN)listzipriter)rKrLr=r=r>batch]srQ Parameter)r0paramr2c csz dVWntyX}z6|jdur*||_|durB|jdurB||_WYd}~n>d}~0ty}z|jdurv||_WYd}~n d}~00dS)z>Context manager that attaches extra information to exceptions.N)rr0rSr)r0rSer=r=r>augment_usage_errorsas   rU)invocation_orderdeclaration_orderr2cs*dtjttfdfdd }t||dS)a Returns all declared parameters in the order they should be processed. The declared parameters are re-shuffled depending on the order in which they were invoked, as well as the eagerness of each parameters. The invocation order takes precedence over the declaration order. I.e. the order in which the user provided them to the CLI is respected. This behavior and its effect on callback evaluation is detailed at: https://click.palletsprojects.com/en/stable/advanced/#callback-evaluation-order rR)itemr2cs6z|}Wnty(td}Yn0|j |fS)Ninf)index ValueErrorfloatis_eager)rXidxrVr=r>sort_keys  z,iter_params_for_processing..sort_keykey)r3Tupleboolr\sorted)rVrWr`r=r_r>iter_params_for_processingtsrfc@s8eZdZdZeZeZeZeZ eZ dS)ParameterSourcea\This is an :class:`~enum.Enum` that indicates the source of a parameter's value. Use :meth:`click.Context.get_parameter_source` to get the source for a parameter by name. .. versionchanged:: 8.0 Use :class:`~enum.Enum` and drop the ``validate`` method. .. versionchanged:: 8.0 Added the ``PROMPT`` value. N) rH __module__ __qualname____doc__enumauto COMMANDLINE ENVIRONMENTDEFAULT DEFAULT_MAPPROMPTr=r=r=r>rgs rgc@s~eZdZUdZeZejded<dTdej dej e ej ej ej e ej ej e ej fej e ej e eej eej eej eej eje ej eje ge fej eej edddd Zeje ej fd d d Zdd d dZej ejeej eej eddddZedUeejddddZeeje ej fd ddZed ddZejeedddZ ejdej fejdej fddd Z!dd d!d"Z"ee d d#d$Z#dd d%d&Z$ejeej ed'd(d)Z%ejeed'd*d+Z&ej'dVe d,ej ej d-d.d/Z(ej'dWe d0ej ej)ej ejgej ffd-d1d/Z(dXe eej ej d-d2d/Z(e d3d4d5d6Z*d3d d7d8Z+dYe d3d:d;d<Z,e d d=d>Z-e d d?d@Z.dddAdBdCZ/ej'dDej ej edEdFdGZ0ej'dej ej ej dEdHdGZ0ej)dIej ej ej)ej efdEdJdGZ0dej ej ej dKdLdMZ1e e2ddNdOdPZ3e ej e2dQdRdSZ4dS)Zr-aThe context is a special internal object that holds state relevant for the script execution at every single level. It's normally invisible to commands unless they opt-in to getting access to it. The context is useful as it can pass internal objects around and can control special execution features such as reading data from environment variables. A context can be used as context manager in which case it will call :meth:`close` on teardown. :param command: the command class for this context. :param parent: the parent context. :param info_name: the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it is usually the name of the script, for commands below it it's the name of the script. :param obj: an arbitrary object of user data. :param auto_envvar_prefix: the prefix to use for automatic environment variables. If this is `None` then reading from environment variables is disabled. This does not affect manually set environment variables which are always read. :param default_map: a dictionary (like object) with default values for parameters. :param terminal_width: the width of the terminal. The default is inherit from parent context. If no context defines the terminal width then auto detection will be applied. :param max_content_width: the maximum width for content rendered by Click (this currently only affects help pages). This defaults to 80 characters if not overridden. In other words: even if the terminal is larger than that, Click will not format things wider than 80 characters by default. In addition to that, formatters might add some safety mapping on the right. :param resilient_parsing: if this flag is enabled then Click will parse without any interactivity or callback invocation. Default values will also be ignored. This is useful for implementing things such as completion support. :param allow_extra_args: if this is set to `True` then extra arguments at the end will not raise an error and will be kept on the context. The default is to inherit from the command. :param allow_interspersed_args: if this is set to `False` then options and arguments cannot be mixed. The default is to inherit from the command. :param ignore_unknown_options: instructs click to ignore options it does not know and keeps them for later processing. :param help_option_names: optionally a list of strings that define how the default help parameter is named. The default is ``['--help']``. :param token_normalize_func: an optional function that is used to normalize tokens (options, choices, etc.). This for instance can be used to implement case insensitive behavior. :param color: controls if the terminal supports ANSI colors or not. The default is autodetection. This is only needed if ANSI codes are used in texts that Click prints which is by default not the case. This for instance would affect help output. :param show_default: Show the default value for commands. If this value is not set, it defaults to the value from the parent context. ``Command.show_default`` overrides this default for the specific command. .. versionchanged:: 8.1 The ``show_default`` parameter is overridden by ``Command.show_default``, instead of the other way around. .. versionchanged:: 8.0 The ``show_default`` parameter defaults to the value from the parent context. .. versionchanged:: 7.1 Added the ``show_default`` parameter. .. versionchanged:: 4.0 Added the ``color``, ``ignore_unknown_options``, and ``max_content_width`` parameters. .. versionchanged:: 3.0 Added the ``allow_extra_args`` and ``allow_interspersed_args`` parameters. .. versionchanged:: 2.0 Added the ``resilient_parsing``, ``help_option_names``, and ``token_normalize_func`` parameters. rformatter_classNFr.)r6parent info_nameobjauto_envvar_prefix default_mapterminal_widthmax_content_widthresilient_parsingallow_extra_argsallow_interspersed_argsignore_unknown_optionshelp_option_namestoken_normalize_funccolor show_defaultr2cCs(||_||_||_i|_g|_g|_|r2t|jnt|_|durP|durP|j}||_t |di|_ |dur|dur|dur|j dur|j |}||_ d|_ |dur|dur|j}||_|dur|dur|j}||_| dur|j} | |_| dur|j} | |_| dur|j} | |_| dur6|dur0|j} ndg} | |_|durV|durV|j}||_| |_|dur|dur|jdur|jdur|jd|j}n|}|dur|dd}||_|dur|dur|j}||_|dur|dur|j}||_g|_d|_i|_t|_dS)Nmetaz--help_-r) rsr6rtparamsargsprotected_argsset _opt_prefixesrugetattr_metarwgetinvoked_subcommandrxryr{r|r}r~rrzrvupperreplacerrZ_close_callbacks_depth_parameter_sourcer _exit_stack)selfr6rsrtrurvrwrxryrzr{r|r}r~rrrr=r=r>__init__ s         zContext.__init__r2cCs$|j||j|j|j|j|jdS)a*Gather information that could be useful for a tool generating user-facing documentation. This traverses the entire CLI structure. .. code-block:: python with Context(cli) as ctx: info = ctx.to_info_dict() .. versionadded:: 8.0 )r6rtr{r|r}rv)r6 to_info_dictrtr{r|r}rvrr=r=r>rs zContext.to_info_dictcCs|jd7_t||SNr )rrrr=r=r> __enter__szContext.__enter__)exc_type exc_valuetbr2cCs*|jd8_|jdkr |tdSNr r)rcloser)rrrrr=r=r>__exit__s zContext.__exit__T)cleanupr2c csl|s|jd7_z@|}|VWdn1s40YW|sh|jd8_n|sf|jd8_0dS)aIThis helper method can be used with the context object to promote it to the current thread local (see :func:`get_current_context`). The default behavior of this is to invoke the cleanup functions which can be disabled by setting `cleanup` to `False`. The cleanup functions are typically used for things such as closing file handles. If the cleanup is intended the context object can also be directly used as a context manager. Example usage:: with ctx.scope(): assert get_current_context() is ctx This is equivalent:: with ctx: assert get_current_context() is ctx .. versionadded:: 5.0 :param cleanup: controls if the cleanup functions should be run or not. The default is to run these functions. In some situations the context only wants to be temporarily pushed in which case this can be disabled. Nested pushes automatically defer the cleanup. r N)r)rrrvr=r=r>scopes&z Context.scopecCs|jS)aThis is a dictionary which is shared with all the contexts that are nested. It exists so that click utilities can store some state here if they need to. It is however the responsibility of that code to manage this dictionary well. The keys are supposed to be unique dotted strings. For instance module paths are a good choice for it. What is stored in there is irrelevant for the operation of click. However what is important is that code that places data here adheres to the general semantics of the system. Example usage:: LANG_KEY = f'{__name__}.lang' def set_language(value): ctx = get_current_context() ctx.meta[LANG_KEY] = value def get_language(): return get_current_context().meta.get(LANG_KEY, 'en_US') .. versionadded:: 5.0 )rrr=r=r>rsz Context.metacCs|j|j|jdS)a=Creates the :class:`~click.HelpFormatter` for the help and usage output. To quickly customize the formatter class used without overriding this method, set the :attr:`formatter_class` attribute. .. versionchanged:: 8.0 Added the :attr:`formatter_class` attribute. )width max_width)rrrxryrr=r=r>make_formatter s zContext.make_formatter)context_managerr2cCs |j|S)aRegister a resource as if it were used in a ``with`` statement. The resource will be cleaned up when the context is popped. Uses :meth:`contextlib.ExitStack.enter_context`. It calls the resource's ``__enter__()`` method and returns the result. When the context is popped, it closes the stack, which calls the resource's ``__exit__()`` method. To register a cleanup function for something that isn't a context manager, use :meth:`call_on_close`. Or use something from :mod:`contextlib` to turn it into a context manager first. .. code-block:: python @click.group() @click.option("--name") @click.pass_context def cli(ctx): ctx.obj = ctx.with_resource(connect_db(name)) :param context_manager: The context manager to enter. :return: Whatever ``context_manager.__enter__()`` returns. .. versionadded:: 8.0 )r enter_context)rrr=r=r> with_resource.szContext.with_resource.fr2cCs |j|S)aRegister a function to be called when the context tears down. This can be used to close resources opened during the script execution. Resources that support Python's context manager protocol which would be used in a ``with`` statement should be registered with :meth:`with_resource` instead. :param f: The function to execute on teardown. )rcallback)rrr=r=r> call_on_closeKs zContext.call_on_closecCs|jt|_dS)zInvoke all close callbacks registered with :meth:`call_on_close`, and exit all context managers entered with :meth:`with_resource`. N)rrrrr=r=r>rWs z Context.closecCsvd}|jdur|j}|jdurn|jjg}t|jjtrZ|jj|D]}|||qDd |d|}| S)zThe computed command path. This is used for the ``usage`` information on the help page. It's automatically created by combining the info names of the chain of contexts to the root. N ) rtrs command_pathrEr6r. get_paramsextendget_usage_piecesjoinlstrip)rrZparent_command_pathrSr=r=r>r`s   zContext.command_pathcCs|}|jdur|j}q|S)zFinds the outermost context.Nrs)rnoder=r=r> find_rootss zContext.find_root) object_typer2cCs*|}|dur&t|j|r|jS|j}qdS)z)Finds the closest object of a given type.N)rErurs)rrrr=r=r> find_objectzs  zContext.find_objectcCs"||}|dur||_}|S)zLike :meth:`find_object` but sets the innermost object to a new instance of `object_type` if it does not exist. N)rru)rrrr=r=r> ensure_objects  zContext.ensure_objectte.Literal[True])r<callr2cCsdSrMr=rr<rr=r=r>lookup_defaultszContext.lookup_defaultzte.Literal[False]cCsdSrMr=rr=r=r>rscCs0|jdur,|j|}|r(t|r(|S|SdS)a*Get the default for a parameter from :attr:`default_map`. :param name: Name of the parameter. :param call: If the default is a callable, call it. Disable to return the callable instead. .. versionchanged:: 8.0 Added the ``call`` parameter. N)rwrcallable)rr<rvaluer=r=r>rs    te.NoReturn)messager2cCst||dS)zAborts the execution of the program with a specific error message. :param message: the error message to fail with. Nr)rrr=r=r>failsz Context.failcCs tdS)zAborts the script.Nr rr=r=r>abortsz Context.abortr)coder2cCs t|dS)z-Exits the application with a given exit code.Nr)rrr=r=r>exitsz Context.exitcCs |j|S)zaHelper method to get formatted usage string for the current context and command. )r6 get_usagerr=r=r>rszContext.get_usagecCs |j|S)z^Helper method to get formatted help page for the current context and command. )r6get_helprr=r=r>rszContext.get_help)r6r2cCst|||j|dS)zvCreate a new context of the same type as this context, but for a new command. :meta private: rtrs)rGr<)rr6r=r=r>_make_sub_contextszContext._make_sub_contextt.Callable[..., V])_Context__callbackrkwargsr2cOsdSrMr=_Context__selfrrrr=r=r>invokeszContext.invokecOsdSrMr=rr=r=r>rs)r.rc Ost|tr||}|jdur"tdntd|j}||}|jD],}|j|vr@|j r@| || |||j<q@|j |n|}t |P|,||i|WdWdS1s0YWdn1s0YdS)aInvokes a command callback in exactly the way it expects. There are two ways to invoke this method: 1. the first argument can be a callback and all other arguments and keyword arguments are forwarded directly to the function. 2. the first argument is a click command object. In that case all arguments are forwarded as well but proper click parameters (options and click arguments) must be keyword arguments and Click will fill in defaults. Note that before Click 3.2 keyword arguments were not properly filled in against the intention of this code and no context was created. For more information about this change and why it was done in a bugfix release see :ref:`upgrade-to-3.2`. .. versionchanged:: 8.0 All ``kwargs`` are tracked in :attr:`params` so they will be passed if :meth:`forward` is called at multiple levels. Nz?The given command does not have a callback that can be invoked.r)rEr.r TypeErrorr3r4rrr< expose_valuetype_cast_value get_defaultupdaterU)rrrrZ other_cmdr0rSr=r=r>rs$      ) _Context__cmdrrr2cOsLt|tstd|jD]}||vr|j|||<q|j|g|Ri|S)azSimilar to :meth:`invoke` but fills in default keyword arguments from the current context if the other command expects it. This cannot invoke callbacks directly, only other commands. .. versionchanged:: 8.0 All ``kwargs`` are tracked in :attr:`params` so they will be passed if ``forward`` is called at multiple levels. zCallback is not a command.)rEr.rrr)rrrrrSr=r=r>forwards  zContext.forward)r<sourcer2cCs||j|<dS)zSet the source of a parameter. This indicates the location from which the value of the parameter was obtained. :param name: The name of the parameter. :param source: A member of :class:`~click.core.ParameterSource`. N)r)rr<rr=r=r>set_parameter_source)szContext.set_parameter_source)r<r2cCs |j|S)aXGet the source of a parameter. This indicates the location from which the value of the parameter was obtained. This can be useful for determining when a user specified a value on the command line that is the same as the default value. It will be :attr:`~click.core.ParameterSource.DEFAULT` only if the value was actually taken from the default. :param name: The name of the parameter. :rtype: ParameterSource .. versionchanged:: 8.0 Returns ``None`` if the parameter was not provided from any source. )rr)rr<r=r=r>get_parameter_source2szContext.get_parameter_source)NNNNNNNFNNNNNNN)T)T).)T)r)5rHrhrirjrrrr3Type__annotations__OptionalstrAnyMutableMappingintrdListCallablerDictrr BaseExceptionr rrIteratorrpropertyrrContextManagerr,rrrrrrroverloadrUnionrrrrrrrrrgrrr=r=r=r>r-s a  - %(        5 c @seZdZUdZeZejeed<dZ dZ dZ d.ej e ej eje ejfddddZeeje ejfd d d Ze d d dZee d ddZee d ddZd/ej e eje ej eejedddZeeje eje dddZeejd ddZee ejddddZejd0ej eje ej e ej e dejd d!d"d#Zejd1ej eje ej e ej e eejejd!d%d#Zd2ej eje ej e ej e eeejejd&d'd#Zd3eje ejfe ej e dd(d)d*Zejejejd+d,d-Z dS)4 BaseCommandaThe base command implements the minimal API contract of commands. Most code will never use this as it does not implement a lot of useful functionality but it can act as the direct subclass of alternative parsing methods that do not depend on the Click parser. For instance, this can be used to bridge Click and other systems like argparse or docopt. Because base commands do not implement a lot of the API that other parts of Click take for granted, they are not supported for all operations. For instance, they cannot be used with the decorators usually and they have no built-in callback system. .. versionchanged:: 2.0 Added the `context_settings` parameter. :param name: the name of the command to use unless a group overrides it. :param context_settings: an optional dictionary with defaults that are passed to the context object. context_classFTN)r<context_settingsr2cCs||_|duri}||_dSrM)r<r)rr<rr=r=r>rfs zBaseCommand.__init__r0r2cCs d|jiS)aiGather information that could be useful for a tool generating user-facing documentation. This traverses the entire structure below this command. Use :meth:`click.Context.to_info_dict` to traverse the entire CLI structure. :param ctx: A :class:`Context` representing this command. .. versionadded:: 8.0 r<r<rr0r=r=r>rws zBaseCommand.to_info_dictrcCsd|jjd|jdSN __class__rHr<rr=r=r>__repr__szBaseCommand.__repr__cCs tddS)NzBase commands cannot get usageNotImplementedErrorrr=r=r>rszBaseCommand.get_usagecCs tddS)NzBase commands cannot get helprrr=r=r>rszBaseCommand.get_help)rtrrsextrar2cKsx|jD]\}}||vr |||<q |j|f||d|}|jdd|||Wdn1sj0Y|S)aThis function when given an info name and arguments will kick off the parsing and create a new :class:`Context`. It does not invoke the actual command callback though. To quickly customize the context class used without overriding this method, set the :attr:`context_class` attribute. :param info_name: the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it's usually the name of the script, for commands below it's the name of the command. :param args: the arguments to parse as list of strings. :param parent: the parent context if available. :param extra: extra keyword arguments forwarded to the context constructor. .. versionchanged:: 8.0 Added the :attr:`context_class` attribute. rFrN)ritemsrr parse_args)rrtrrsrrbrr0r=r=r> make_contexts *zBaseCommand.make_contextr0rr2cCs tddS)zGiven a context and a list of arguments this creates the parser and parses the arguments, then modifies the context as necessary. This is automatically invoked by :meth:`make_context`. z1Base commands do not know how to parse arguments.Nr)rr0rr=r=r>rszBaseCommand.parse_argscCs tddS)z{Given a context, this invokes the command. The default implementation is raising a not implemented error. z*Base commands are not invocable by defaultNrrr=r=r>rszBaseCommand.invoker)r/csZddlmg}jdurVjtjtrjjr|fddt|Dq|S)aReturn a list of completions for the incomplete value. Looks at the names of chained multi-commands. Any command could be part of a chained multi-command, so sibling commands are valid at any point during command completion. Other command classes will return more completions. :param ctx: Invocation context for this command. :param incomplete: Value being completed. May be empty. .. versionadded:: 8.0 rr(Nc3s,|]$\}}|jvr||dVqdShelpN)rget_short_help_str.0r<r6r)r0r=r> s z-BaseCommand.shell_complete..) click.shell_completionr)rsrEr6r5rDrr?rr0r1resultsr=rr>shell_completes   zBaseCommand.shell_completerr)r prog_name complete_varstandalone_moderr2cKsdSrMr=rrr r r rr=r=r>mainszBaseCommand.main.cKsdSrMr=rr=r=r>rs)rr r r windows_expand_argsrr2c Ks.|dur.tjdd}tjdkr6|r6t|}nt|}|durDt}||||zRzd|j||fi|<}| |}|s|WdWWS| Wdn1s0YWnt t fy} z t tjdt| WYd} ~ nd} ~ 0ty6} z(|s| t | jWYd} ~ nvd} ~ 0ty} zT| jtjkrttjttjt_ttjttjt_t dnWYd} ~ n d} ~ 00Wnty} z2|rt | jn| jWYd} ~ SWYd} ~ n@d} ~ 0ty(|st tdtjdt dYn0dS)aThis is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, ``SystemExit`` needs to be caught. This method is also available by directly calling the instance of a :class:`Command`. :param args: the arguments that should be used for parsing. If not provided, ``sys.argv[1:]`` is used. :param prog_name: the program name that should be used. By default the program name is constructed by taking the file name from ``sys.argv[0]``. :param complete_var: the environment variable that controls the bash completion support. The default is ``"__COMPLETE"`` with prog_name in uppercase. :param standalone_mode: the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to `False` they will be propagated to the caller and the return value of this function is the return value of :meth:`invoke`. :param windows_expand_args: Expand glob patterns, user dir, and env vars in command line args on Windows. :param extra: extra keyword arguments are forwarded to the context constructor. See :class:`Context` for more information. .. versionchanged:: 8.0.1 Added the ``windows_expand_args`` parameter to allow disabling command line arg expansion on Windows. .. versionchanged:: 8.0 When taking arguments from ``sys.argv`` on Windows, glob patterns, user dir, and env vars are expanded. .. versionchanged:: 3.0 Added the ``standalone_mode`` parameter. Nr nt)filezAborted!)sysargvosr<r!rNr _main_shell_completionrrrEOFErrorKeyboardInterruptr"stderrr rshow exit_codeOSErrorerrnoEPIPEr3r4TextIOr%stdoutrr) rrr r r rrr0rrTr=r=r>rsL3  *    &)ctx_argsr r r2cCsj|dur,|dddd}d|d}tj|}|s@dSddlm}||||||}t|dS)aCheck if the shell is asking for tab completion, process that, then exit early. Called from :meth:`main` before the program is invoked. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds the completion instruction. Defaults to ``_{PROG_NAME}_COMPLETE``. .. versionchanged:: 8.2.0 Dots (``.``) in ``prog_name`` are replaced with underscores (``_``). Nrr.Z _COMPLETEr )r ) rrrenvironrshell_completionr rr)rr!r r Z complete_nameZ instructionr rr=r=r>rgs  z"BaseCommand._main_shell_completionrrr2cOs|j|i|S)zAlias for :meth:`main`.)rrrrr=r=r>__call__szBaseCommand.__call__)N)N)NNNT)NNN.)NNNTT)N)!rHrhrirjr-rr3rrr{r|r}rrrrrrrrrrrrrrr rSequencerrdrr'r=r=r=r>rEs   *   u rcseZdZdZd5ejeejejeejfejej dejfejej dejeejeejeejee e e e dd fd d Z e ejeejfd fd d Ze ed ddZe ej dd ddZe eddddZe ej ed ddZe ej ed ddZe ejdd ddZe ed ddZe ed ddZd6eed!d"d#Ze eddd$d%Ze eddd&d'Ze eddd(d)Ze eddd*d+Ze ej eej ed,d-d.Z e ejd d/d0Z!e eej d1d2fd3d4 Z"Z#S)7r.aCommands are the basic building block of command line interfaces in Click. A basic command handles command line parsing and might dispatch more parsing to commands nested below it. :param name: the name of the command to use unless a group overrides it. :param context_settings: an optional dictionary with defaults that are passed to the context object. :param callback: the callback to invoke. This is optional. :param params: the parameters to register with this command. This can be either :class:`Option` or :class:`Argument` objects. :param help: the help string to use for this command. :param epilog: like the help string but it's printed at the end of the help page after everything else. :param short_help: the short help to use for this command. This is shown on the command listing of the parent command. :param add_help_option: by default each command registers a ``--help`` option. This can be disabled by this parameter. :param no_args_is_help: this controls what happens if no arguments are provided. This option is disabled by default. If enabled this will add ``--help`` as argument if no arguments are passed :param hidden: hide this command from help outputs. :param deprecated: issues a message indicating that the command is deprecated. .. versionchanged:: 8.1 ``help``, ``epilog``, and ``short_help`` are stored unprocessed, all formatting is done when outputting help text, not at init, and is done even if not using the ``@command`` decorator. .. versionchanged:: 8.0 Added a ``repr`` showing the command name. .. versionchanged:: 7.1 Added the ``no_args_is_help`` parameter. .. versionchanged:: 2.0 Added the ``context_settings`` parameter. N [OPTIONS]TF.rR) r<rrrrepilog short_helpoptions_metavaradd_help_optionno_args_is_helpr: deprecatedr2c sXt||||_|pg|_||_||_||_||_| |_d|_ | |_ | |_ | |_ dSrM) superrrrrr*r,r+r- _help_optionr.r:r/) rr<rrrrr*r+r,r-r.r:r/rr=r>rs zCommand.__init__rcs@t|}|jdd||D|j|j|j|j|jd|S)NcSsg|] }|qSr=)r)rrSr=r=r> z(Command.to_info_dict..)rrr*r+r:r/) r0rrrrr*r+r:r/)rr0 info_dictr2r=r>rs zCommand.to_info_dictcCs"|}||||dS)zmFormats the usage line into a string and returns it. Calls :meth:`format_usage` internally.  )r format_usagegetvaluerstriprr0 formatterr=r=r>rs zCommand.get_usagecCs(|j}||}|dur$g||}|SrM)rget_help_option)rr0r help_optionr=r=r>rs   zCommand.get_paramsr0r;r2cCs"||}||jd|dS)zsWrites the usage line into the formatter. This is a low-level method called by :meth:`get_usage`. rN)collect_usage_piecesZ write_usagerr)rr0r;piecesr=r=r>r7s zCommand.format_usagecCs6|jr|jgng}||D]}|||q|S)zhReturns all the pieces that go into the usage line and returns it as a list of strings. )r,rrr)rr0rrSr=r=r>r?szCommand.collect_usage_piecescCs6t|j}|jD]}||j||jqt|S)z&Returns the names for the help option.)rr~rdifference_updateoptssecondary_optsrN)rr0Z all_namesrSr=r=r>get_help_option_namess    zCommand.get_help_option_namesOptioncCs>||}|r|jsdS|jdur8ddlm}|||_|jS)zReturns the help option object. Unless ``add_help_option`` is ``False``. .. versionchanged:: 8.1.8 The help option is now cached to avoid creating it multiple times. Nr r&)rDr-r1 decoratorsr')rr0 help_optionsr'r=r=r>r<s     zCommand.get_help_optioncCs(t|}||D]}|||q|S)z6Creates the underlying option parser for this command.)rr add_to_parser)rr0parserrSr=r=r> make_parser)szCommand.make_parsercCs"|}||||dS)zfFormats the help into a string and returns it. Calls :meth:`format_help` internally. r6)r format_helpr8r9r:r=r=r>r0s zCommand.get_help-)limitr2cCsJ|jrt|j}n|jr(t|j|}nd}|jrBtdj|d}|S)z`Gets short help for the command or makes it by shortening the long help string. r(Deprecated) {text}text) r+inspectcleandocrr#r/rformatstrip)rrMrPr=r=r>r9szCommand.get_short_help_strcCs4||||||||||||dS)a0Writes the help into the formatter if it exists. This is a low-level method called by :meth:`get_help`. This calls the following methods: - :meth:`format_usage` - :meth:`format_help_text` - :meth:`format_options` - :meth:`format_epilog` N)r7format_help_textformat_options format_epilogr:r=r=r>rKIs   zCommand.format_helpcCs~|jdur"t|jdd}nd}|jrrUZs  zCommand.format_help_textcCspg}||D] }||}|dur||q|rl|td||Wdn1sb0YdS)z8Writes all the options into the formatter if they exist.NOptions)rget_help_recordappendsectionrwrite_dl)rr0r;rBrSrr=r=r>rVks  zCommand.format_optionscCsP|jrLt|j}||||Wdn1sB0YdS)z2Writes the epilog into the formatter if it exists.N)r*rQrRrZr[r\)rr0r;r*r=r=r>rWws   zCommand.format_epilogrcCs|s*|jr*|js*t||jd|||}|j|d\}}}t|| |D]}| |||\}}qV|r|j s|js| t ddt|jdtt|d||_|j|j|S)Nr)rz&Got unexpected extra argument ({args})z'Got unexpected extra arguments ({args})r)r.rzr"rrrrJrrfrhandle_parse_resultr{rrlenrSrmaprrrr)rr0rrIrBZ param_orderrSrr=r=r>rs( zCommand.parse_argscCsP|jr,tdj|jd}tt|dddd|jdurL|j|jfi|jSdS)zeGiven a context, this invokes the attached callback (if it exists) in the right way. z7DeprecationWarning: The command {name!r} is deprecated.rred)ZfgT)errN) r/rrSr<r"rrrr)rr0rr=r=r>rs zCommand.invoker)r/csddlmg}rds||D]Vttr*js*jsX|j t j urXq*| fddgj jDq*| t||S)aReturn a list of completions for the incomplete value. Looks at the names of options and chained multi-commands. :param ctx: Invocation context for this command. :param incomplete: Value being completed. May be empty. .. versionadded:: 8.0 rr(c3s&|]}|r|jdVqdSr)r8r)rr<r)r1rSr=r>rs z)Command.shell_complete..)rr)isalnumrrErEr:multiplerr<rgrmrrBrCr0r rr2rhr>r s(    zCommand.shell_complete) NNNNNNr)TFFF)rL)$rHrhrirjr3rrrrrrrdrr-rrrrrr7r?rDr<rrJrrrrKrUrVrWrrr  __classcell__r=r=r2r>r.sX,!        c seZdZdZdZdZd&ejee eje ejee ejej dej fej ddfdd Z e ejeej fd fd d Ze ejed fd d Ze eddfdd Zd'e ej egefdddZe eddddZe ejeejedfdd Ze ej d fdd Ze ejeejejeejeejefdddZe eejedddZe ejed d d!Ze eejd"d#fd$d% ZZS)(r5aA multi command is the basic implementation of a command that dispatches to subcommands. The most common version is the :class:`Group`. :param invoke_without_command: this controls how the multi command itself is invoked. By default it's only invoked if a subcommand is provided. :param no_args_is_help: this controls what happens if no arguments are provided. This option is enabled by default if `invoke_without_command` is disabled or disabled if it's enabled. If enabled this will add ``--help`` as argument if no arguments are passed. :param subcommand_metavar: the string that is used in the documentation to indicate the subcommand place. :param chain: if this is set to `True` chaining of multiple subcommands is enabled. This restricts the form of commands in that they cannot have optional arguments but it allows multiple commands to be chained together. :param result_callback: The result callback to attach to this multi command. This can be set or changed later with the :meth:`result_callback` decorator. :param attrs: Other command arguments described in :class:`Command`. TFN.)r<invoke_without_commandr.subcommand_metavarrDresult_callbackattrsr2c  stj|fi||dur"| }||_||_|durD|r@d}nd}||_||_||_|jr|jD]}t|t rb|j sbt dqbdS)Nz*COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...zCOMMAND [ARGS]...zrs$  zMultiCommand.__init__rc st|}i}||D]^}|||}|dur4q||}|jdd||||<Wdq1sn0Yq|j||jd|S)NFr)commandsrD)r0rr7r9rrrrD)rr0r5rsr<r6sub_ctxr2r=r>r s   .zMultiCommand.to_info_dictcst|}||j|SrM)r0r?r_rmrr0rr2r=r>r?s  z!MultiCommand.collect_usage_piecesr>cst|||||dSrM)r0rVformat_commandsr:r2r=r>rV#szMultiCommand.format_options)rr2csttdfdd }|S)aAdds a result callback to the command. By default if a result callback is already registered this will chain them but this can be disabled with the `replace` parameter. The result callback is invoked with the return value of the subcommand (or the list of return values from all subcommands if chaining is enabled) as well as the parameters as they would be passed to the main callback. Example:: @click.group() @click.option('-i', '--input', default=23) def cli(input): return 42 @cli.result_callback() def process_result(result, input): return result + input :param replace: if set to `True` an already existing result callback will be removed. .. versionchanged:: 8.0 Renamed from ``resultcallback``. .. versionadded:: 3.0 rcsFjdusr_Sfdd}ttt|_}|S)Ncs,|g|Ri|}|g|Ri|SrMr=)Z_MultiCommand__valuerrinnerrZ old_callbackr=r>functionKszAMultiCommand.result_callback..decorator..function)rprr3r4r*)rryrrrrxr> decoratorDs z/MultiCommand.result_callback..decorator)r*)rrr{r=rzr>rn'szMultiCommand.result_callbackc Csg}||D]0}|||}|dur(q|jr0q|||fqt|r|jdtdd|D}g}|D] \}}||}|||fql|r|t d| |Wdn1s0YdS)zeExtra format methods for multi methods that adds all the commands after the options. Ncss|]}t|dVqdS)rNrd)rrBr=r=r>rer4z/MultiCommand.format_commands..Commands) r7r9r:r_rdrmaxrr`rra) rr0r;rs subcommandrBrMrowsrr=r=r>rvTs"   zMultiCommand.format_commandsrcst|s*|jr*|js*t||jd|t||}|jrL||_ g|_ n"|rn|dd|dd|_ |_ |j S)Nrbr ) r.rzr"rrrr0rrDrr)rr0rrestr2r=r>rpszMultiCommand.parse_argsc s4tjtjdfdd }jsvjrh.t}|jrDgn|WdS1s^0Ytdgjj }g_ g_jsD |\}}}|dusJ|_ t|j ||d}|.||j |WdWdS1s0YWdn1s:0Y|rTdnd_ tg}|r |\}}}|dusJ|j ||ddd }|||j g}|_ qjg}|D]>}|"||j |Wdn1s0Yq||WdS1s&0YdS) Nrr2cs&jdur"jj|fij}|SrM)rprrrr0rr=r>_process_results z,MultiCommand.invoke.._process_resultzMissing command.r*TF)rsr{r|)r3rrrlr0rrDrrrresolve_commandrrr6r_) rr0rrrrArBrtZcontextsr2rr>rsP 0  ^  6zMultiCommand.invokecCst|d}|}|||}|durD|jdurD||}|||}|dur|jst|drl|||j|tdj |d|r|nd||ddfS)NrzNo such command {name!r}.rr ) r$r9rrzrrrrrrS)rr0rrAZoriginal_cmd_namerBr=r=r>rs     zMultiCommand.resolve_commandr0rAr2cCstdS)z{Given a context and a command name, this returns a :class:`Command` object if it exists or returns `None`. Nrrr0rAr=r=r>r9szMultiCommand.get_commandcCsgS)zTReturns a list of subcommand names in the order they should appear. r=rr=r=r>r7szMultiCommand.list_commandsr)r/cs<ddlmfddt||D}|t|||S)a0Return a list of completions for the incomplete value. Looks at the names of options, subcommands, and chained multi-commands. :param ctx: Invocation context for this command. :param incomplete: Value being completed. May be empty. .. versionadded:: 8.0 rr(cs g|]\}}||dqS)r)rrr(r=r>r3sz/MultiCommand.shell_complete..)rr)r?rr0r rr2r(r>r s  zMultiCommand.shell_complete)NFNNFN)F) rHrhrirjr{r|r3rrrdrrrr-rrrr?rrVr*rnrvrrrcr.rr9r7r rkr=r=r2r>r5s@& -"E  cseZdZUdZdZejejee d<dZ ejej ejdeje fe d<deje ejej eje efejefejddfdd Zdeeje ddd d Zejejd ejfed d dZejejejejejd ejfgefdddZejejej ejejd ejfgefefdddZejejd ejfdd ddZejejejejejd ejfgdfdddZejejej ejejd ejfgdfdfdddZee ejedddZeeje dddZZS)GroupaMA group allows a command to have subcommands attached. This is the most common way to implement nesting in Click. :param name: The name of the group command. :param commands: A dict mapping names to :class:`Command` objects. Can also be a list of :class:`Command`, which will use :attr:`Command.name` to create the dict. :param attrs: Other command arguments described in :class:`MultiCommand`, :class:`Command`, and :class:`BaseCommand`. .. versionchanged:: 8.0 The ``commands`` argument can be a list of command objects. N command_class group_class)r<rsror2c sFtj|fi||dur"i}nt|tjr /r4z"Group.__init__..)r0rrErr(rs)rr<rsror2r=r>r"s  zGroup.__init__)rBr<r2cCs8|p|j}|durtdt|||dd||j|<dS)zRegisters another :class:`Command` with this group. If the name is not provided, the name of the command is used. NzCommand has no name.T)rC)r<rrJrs)rrBr<r=r=r> add_command4s  zGroup.add_command.) _Group__funcr2cCsdSrMr=rrr=r=r>r6>sz Group.commandr%cOsdSrMr=r&r=r=r>r6Ascsddlmd}rBtdrBtdkr0r8Jd\}djr`ddur`jd<tjdtjft d fd d }|dur||S|S) aA shortcut decorator for declaring and attaching a command to the group. This takes the same arguments as :func:`command` and immediately registers the created command with this group by calling :meth:`add_command`. To customize the command class used, set the :attr:`command_class` attribute. .. versionchanged:: 8.1 This decorator can be applied without parentheses. .. versionchanged:: 8.0 Added the :attr:`command_class` attribute. r )r6Nrz7Use 'command(**kwargs)(callable)' to provide arguments.r=cls.rcs i|}||SrMrrrBrr6rrr=r>r{es z Group.command..decorator) rFr6rrdrrr3rrr.rrrfuncr{r=rr>r6Fs"   &cCsdSrMr=rr=r=r>grouposz Group.groupcOsdSrMr=r&r=r=r>rrscsddlmd}rBtdrBtdkr0r8Jd\}djdur|ddur|jturrtd<n jd<tjdtj fd d fd d }|dur||S|S) aA shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as :func:`group` and immediately registers the created group with this group by calling :meth:`add_command`. To customize the group class used, set the :attr:`group_class` attribute. .. versionchanged:: 8.1 This decorator can be applied without parentheses. .. versionchanged:: 8.0 Added the :attr:`group_class` attribute. r )rNrz5Use 'group(**kwargs)(callable)' to provide arguments.r=r.rrcs i|}||SrMrrrrrrr=r>r{s zGroup.group..decorator) rFrrrdrrrGr3rrrr=rr>rws&    &rcCs |j|SrM)rsrrr=r=r>r9szGroup.get_commandrcCs t|jSrM)rersrr=r=r>r7szGroup.list_commands)NN)N)rHrhrirjrr3rrr.rrrrGrrr(rrrrrr6rr-r9rr7rkr=r=r2r>rsD  ( $ )$ ,rcseZdZdZdejeejejeej ddfdd Z eddddZ e eeje d d d Ze ejed d dZZS)CommandCollectionakA command collection is a multi command that merges multiple multi commands together into one. This is a straightforward implementation that accepts a list of different multi commands as sources and provides all the commands for each of them. See :class:`MultiCommand` and :class:`Command` for the description of ``name`` and ``attrs``. N)r<sourcesror2c s"tj|fi||pg|_dSrM)r0rr)rr<rror2r=r>rszCommandCollection.__init__) multi_cmdr2cCs|j|dS)z1Adds a new multi command to the chain dispatcher.N)rr_)rrr=r=r> add_sourceszCommandCollection.add_sourcercCs>|jD]2}|||}|dur|jr0t||||SqdSrM)rr9rDrJ)rr0rArrr=r=r>r9s    zCommandCollection.get_commandrcCs*t}|jD]}|||q t|SrM)rrrr7re)rr0rrr=r=r>r7s zCommandCollection.list_commands)NN)rHrhrirjr3rrrr5rrrr-r.r9r7rkr=r=r2r>rs   rrcCst|trtt|S)ztCheck if the value is iterable but not a string. Raises a type error, or return an iterator over the value. )rErrrPrr=r=r> _check_iters rc@s*eZdZdZdZdee ejej ej ejgej ffdddZd?ee ejej ej ejgej ffdddZeeddddZeejeej fejej e fd d!d"Z!eej ej d#d$d%Z"ej e d&d'd(Z#eej ej d#d)d*Z$eejed+d,d-Z%eejej d+d.d/Z&eejeej fejeejej ejefd0d1d2Z'eejejeefd+d3d4Z(eejed+d5d6Z)eed+d7d8Z*eeejdd9d:d;Z+dS)@rRaA parameter to a command comes in two versions: they are either :class:`Option`\s or :class:`Argument`\s. Other subclasses are currently not supported by design as some of the internals for parsing are intentionally not finalized. Some settings are supported by both options and arguments. :param param_decls: the parameter declarations for this option or argument. This is a list of flags or argument names. :param type: the type that should be used. Either a :class:`ParamType` or a Python type. The latter is converted into the former automatically if supported. :param required: controls if this is optional or not. :param default: the default value if omitted. This can also be a callable, in which case it's invoked when the default is needed without any arguments. :param callback: A function to further process or validate the value after type conversion. It is called as ``f(ctx, param, value)`` and must return the value. It is called for all sources, including prompts. :param nargs: the number of arguments to match. If not ``1`` the return value is a tuple instead of single value. The default for nargs is ``1`` (except if the type is a tuple, then it's the arity of the tuple). If ``nargs=-1``, all remaining parameters are collected. :param metavar: how the value is represented in the help page. :param expose_value: if this is `True` then the value is passed onwards to the command callback and stored on the context, otherwise it's skipped. :param is_eager: eager values are processed before non eager ones. This should not be set for arguments or it will inverse the order of processing. :param envvar: a string or list of strings that are environment variables that should be checked. :param shell_complete: A function that returns custom shell completions. Used instead of the param's type completion if given. Takes ``ctx, param, incomplete`` and must return a list of :class:`~click.shell_completion.CompletionItem` or a list of strings. .. versionchanged:: 8.0 ``process_value`` validates required parameters and bounded ``nargs``, and invokes the parameter callback before returning the value. This allows the callback to validate prompts. ``full_process_value`` is removed. .. versionchanged:: 8.0 ``autocompletion`` is renamed to ``shell_complete`` and has new semantics described above. The old name is deprecated and will be removed in 8.1, until then it will be wrapped to match the new requirements. .. versionchanged:: 8.0 For ``multiple=True, nargs>1``, the default must be a list of tuples. .. versionchanged:: 8.0 Setting a default is no longer required for ``nargs>1``, it will default to ``None``. ``multiple=True`` or ``nargs=-1`` will default to ``()``. .. versionchanged:: 7.1 Empty environment variables are ignored rather than taking the empty string value. This makes it possible for scripts to clear variables if they can't unset them. .. versionchanged:: 2.0 Changed signature for parameter callback to also be passed the parameter. The old callback format will still work, but it will raise a warning to give you a chance to migrate the code easier. Z parameterNFTr)) param_declsrGrrdefaultrnargsrjmetavarrr]envvarr r2c Cs|||||pd| \|_|_|_t|||_|durT|jjrP|jj}nd}||_ ||_ ||_ ||_ | |_ ||_| |_||_| |_| |_|jjr||jjkrtd|jjd|jd|dt|s|nd} | dur|rztt| d} WntytddYn0|dkr| durz t| Wn.tyf|rTd}nd }t|dYn0|dkrt| |kr|rd nd }td |d |ddS)Nr=r z'nargs' must be z (or None) for type z , but it was r"z1'default' must be a list when 'multiple' is true.zK'default' must be a list of lists when 'multiple' is true and 'nargs' != 1.z+'default' must be a list when 'nargs' != 1.z item lengthlengthz 'default' z must match nargs=) _parse_declsr<rBrCr convert_typerG is_compositeZarityrrrrrjrrr]rr_custom_shell_completer[rnextrrrd)rrrGrrrrrrjrrr]rr  check_defaultrsubjectr=r=r>r-sl    zParameter.__init__rc Cs2|j|j|j|j|j|j|j|j|j |j d S)zGather information that could be useful for a tool generating user-facing documentation. Use :meth:`click.Context.to_info_dict` to traverse the entire CLI structure. .. versionadded:: 8.0 ) r<param_type_namerBrCrGrrrrjrr) r<rrBrCrGrrrrrjrrrr=r=r>rs zParameter.to_info_dictcCsd|jjd|jdSrrrr=r=r>rszParameter.__repr__declsrr2cCs tdSrMr)rrrr=r=r>rszParameter._parse_declscCs|jS)zReturns the human readable name of this parameter. This is the same as the name for options, but the metavar for arguments. rrr=r=r>human_readable_nameszParameter.human_readable_namecCsF|jdur|jS|j|}|dur0|jj}|jdkrB|d7}|S)Nr ...)rrG get_metavarr<rr)rrr=r=r> make_metavars    zParameter.make_metavarrr0rr2cCsdSrMr=rr0rr=r=r>rszParameter.get_default.cCsdSrMr=rr=r=r>rscCs4|j|jdd}|dur|j}|r0t|r0|}|S)aGet the default for the parameter. Tries :meth:`Context.lookup_default` first, then the local default. :param ctx: Current context. :param call: If the default is a callable, call it. Disable to return the callable instead. .. versionchanged:: 8.0.2 Type casting is no longer performed when getting a default. .. versionchanged:: 8.0.1 Type casting can fail in resilient parsing mode. Invalid defaults will not prevent showing help text. .. versionchanged:: 8.0 Looks at ``ctx.default_map`` first. .. versionchanged:: 8.0 Added the ``call`` parameter. FrN)rr<rr)rr0rrr=r=r>rs  rIr0r2cCs tdSrMrrrIr0r=r=r>rHszParameter.add_to_parserr0rBr2cCsd||j}tj}|dur*||}tj}|durD||j}tj}|dur\||}tj }||fSrM) rr<rgrmvalue_from_envvarrnrrprrorr0rBrrr=r=r> consume_values    zParameter.consume_value)r0rr2cs|dur jsjdkrdSdStjtjtjdfdd jdksRjjrntjtjdfdd nDjdkrtjtjdfd d ntjtjdfd d jrtfd d |DS|S)zuConvert and validate a value against the option's :attr:`type`, :attr:`multiple`, and :attr:`nargs`. Nr=rcs6z t|WSty0ttdddYn0dS)NzValue must be an iterable.r0rS)rrrrrrr=r> check_iter s   z-Parameter.type_cast_value..check_iterr csj|dS)N)rSr0rGrrr=r>convert sz*Parameter.type_cast_value..convertcstfdd|DS)Nc3s|]}|VqdSrMrrxrr=r>r r4=Parameter.type_cast_value..convert..)tuplerrr0rr=r>r scs\t|}t|jkrDttddt|jjt|ddtfdd|DS)Nz%Takes {nargs} values but 1 was given.z*Takes {nargs} values but {len} were given.)rrdrc3s|]}|VqdSrMrrrr=r>r& r4r)rrdrrrrSrrr=r>r s   c3s|]}|VqdSrMr=r)rr=r>r) r4z,Parameter.type_cast_value..)rjrr3rrrGrrrr0rr=)rrr0rr>rs  zParameter.type_cast_valuercCs,|dur dS|jdks|jr(|dkr(dSdS)NTr r=F)rrj)rrr=r=r>value_is_missing- s zParameter.value_is_missingcCsD|||}|jr(||r(t||d|jdur@||||}|S)Nr)rrrrrrrr=r=r> process_value6 s    zParameter.process_valuercCsZ|jdurdSt|jtr2tj|j}|rV|Sn$|jD]}tj|}|r8|Sq8dSrM)rrErrr#rrr0rrr=r=r>resolve_envvar_valueA s     zParameter.resolve_envvar_valuecCs,||}|dur(|jdkr(|j|}|Sr)rrrGsplit_envvar_valuerur=r=r>rS s  zParameter.value_from_envvar)r0rBrr2c Cst||d^|||\}}||j|z|||}WntyZ|jsRd}Yn0Wdn1sp0Y|jr||j|j<||fS)N)rS) rUrrr<r Exceptionrzrr)rr0rBrrrr=r=r>rc[ s ( zParameter.handle_parse_resultcCsdSrMr=rr=r=r>r^o szParameter.get_help_recordcCsgSrMr=rr=r=r>rr szParameter.get_usage_piecescCs"|jp |jg}ddd|DS)z{Get a stringified version of the param for use in error messages to indicate which param caused the error.  / css|]}d|dVqdS)'Nr=rr=r=r>rz r4z+Parameter.get_error_hint..)rBrr)rr0Z hint_listr=r=r>get_error_hintu szParameter.get_error_hintr/csj|jdurZ||||}|rHt|dtrHddlmfdd|D}ttjd|S|j |||S)aReturn a list of completions for the incomplete value. If a ``shell_complete`` function was given during init, it is used. Otherwise, the :attr:`type` :meth:`~click.types.ParamType.shell_complete` function is used. :param ctx: Invocation context for this command. :param incomplete: Value being completed. May be empty. .. versionadded:: 8.0 Nrr(csg|] }|qSr=r=rr(r=r>r3 r4z,Parameter.shell_complete..r)) rrErrr)r3r4rrGr rr=r(r>r | s  zParameter.shell_complete) NNFNNNFNTFNN)T).)T),rHrhrirjrr3rr(rrr ParamTyperrdrr-rrrrrrrcrrrrrrrrHMappingrgrrrrrrrcr^rrr r=r=r=r>rRsI  X     ! 3     cs*eZdZdZdZd&ejejeej e edfej e efej e efe e eje ejej e e e ejej e j ej fejee e e ej ddfdd Zejeej fd fd d Zejee ejejeejeejefd d dZeeddddZeejejeefdddZejd'edejej dddZejd(ee ejej ej ejgej ffdddZd)ee ejej ej ejgej ffdfdd Zeej dddZeejedfdd Zeejej dd d!Zeejed"fejej efd#fd$d% Z Z!S)*rEa Options are usually optional values on the command line and have some extra features that arguments don't have. All other parameters are passed onwards to the parameter constructor. :param show_default: Show the default value for this option in its help text. Values are not shown by default, unless :attr:`Context.show_default` is ``True``. If this value is a string, it shows that string in parentheses instead of the actual value. This is particularly useful for dynamic options. For single option boolean flags, the default remains hidden if its value is ``False``. :param show_envvar: Controls if an environment variable should be shown on the help page. Normally, environment variables are not shown. :param prompt: If set to ``True`` or a non empty string then the user will be prompted for input. If set to ``True`` the prompt will be the option name capitalized. :param confirmation_prompt: Prompt a second time to confirm the value if it was prompted for. Can be set to a string instead of ``True`` to customize the message. :param prompt_required: If set to ``False``, the user will be prompted for input only when the option was specified as a flag without a value. :param hide_input: If this is ``True`` then the input on the prompt will be hidden from the user. This is useful for password input. :param is_flag: forces this option to act as a flag. The default is auto detection. :param flag_value: which value should be used for this flag if it's enabled. This is set to a boolean automatically if the option string contains a slash to mark two options. :param multiple: if this is set to `True` then the argument is accepted multiple times and recorded. This is similar to ``nargs`` in how it works but supports arbitrary number of arguments. :param count: this flag makes an option increment an integer. :param allow_from_autoenv: if this is enabled then the value of this parameter will be pulled from an environment variable in case a prefix is defined on the context. :param help: the help string. :param hidden: hide this option from help outputs. :param attrs: Other command arguments described in :class:`Parameter`. .. versionchanged:: 8.1.0 Help text indentation is cleaned here instead of only in the ``@option`` decorator. .. versionchanged:: 8.1.0 The ``show_default`` parameter overrides ``Context.show_default``. .. versionchanged:: 8.1.0 The default of a single option boolean flag is not shown if the default value is ``False``. .. versionchanged:: 8.0.1 ``type`` is detected from ``flag_value`` if given. optionNFT)rrrconfirmation_promptprompt_required hide_inputis_flag flag_valuerjcountallow_from_autoenvrGrr: show_choices show_envvarror2c sT| rt| } d|v}tj|f| | d||dur^|jdurJtd|jdd}n|durld}n|}||_||_ ||_ ||_ ||_ |jduo|j |_ |dur|durd}q|j rd}qt|j}n|dur|j s|du|_ ||r|r|js| rd|_nd|_|dur&|j }||rH| durHtd||_||_|o`t|jtj|_||_| |_| r| durtjd d |_|rd |_| |_| |_||_||_||_ |j!d krtd |jr|jr|jstd |js|jrtd|jr(|j r(|jdur(td|jrP|j"r@td|jrPtddS)Nr)rGrjTz&'name' is required with 'prompt=True'.rrFr=r)minrz&nargs=-1 is not supported for options.z+'prompt' is not valid for non-boolean flag.z1Secondary flag is not valid for non-boolean flag.z9'prompt' with 'hide_input' is not valid for boolean flag.z%'count' is not valid with 'multiple'.z$'count' is not valid with 'is_flag'.)#rQrRr0rr<rr capitalizerrrrr:rrdrCrrrr rrGrrEZ BoolParamType is_bool_flagrrZIntRangerrrrrrrj)rrrrrrrrrrjrrrGrr:rrroZdefault_is_missingZ prompt_textr2r=r>r s       zOption.__init__rcs0t}|j|j|j|j|j|j|jd|S)N)rrrrrr:) r0rrrrrrrr:)rr5r2r=r>rI s zOption.to_info_dictrc Cszg}g}d}g}|D]}|r>|dur8td|d|}q|dddkrRdnd}||vr||d\} } | } | r|t| || | } | r|| | | krtd|dq|t|||q|dur&|r&|jdd d |d d d d  }|s&d}|durN|s@d||fStd||sp|sptd|d|d|||fS)NzName 'z' defined twicer /;zBoolean option z) cannot use the same flag for true/false.cSst|d S)Nrr}rr=r=r>w r4z%Option._parse_decls..rarrrz6Could not determine name for option with declarations z*No options defined but a name was passed (zH). Did you mean to declare an argument instead? Did you mean to pass '--z'?) isidentifierrsplitr9r_rrr[sortrlower) rrrrBrCr<Zpossible_namesdeclZ split_charfirstsecondr=r=r>rU sV       zOption._parse_declsrcCs|jr d}n|jrd}nd}|jr|d}|jrj|jrj|j||j|j|dd|j||j|j|ddq|j||j|j||jdn|j||j|j||j ddS) Nr_rstoreZ_constT)rurBdestactionconstF)rurBrrr) rjrrrrC add_optionrBr<rr)rrIr0rr=r=r>rH s@  zOption.add_to_parserrcsjr dSdtjttdfdd }|jg}jrL||jjpTd}g}jrވj }|durj r|j durj dur|j dj }|durt|tr|nddd |D}|td j|d |j}d |_zj|dd } W||_n||_0d} d} jdur@tjtr8d } } nj} n|jdurR|j} | sh| r:| dur:| r~djd} nt| ttfrddd | D} nzt| rtd} ndjrjrt| r؈jnjdd} n4jrjs| sd} n| dkrd} nt| } | r:|tdj| dtjtjrjrnjjdkrnjj dusj!} | r|| j"r|td|rd|}|r|d|dn d|d}rdnd||fS)NF)rBr2cs6t|\}}|rdjs2js2|d7}|S)NTr)rrrr)rBrZ any_slashesZany_prefix_is_slashrr=r> _write_opts s   z+Option.get_help_record.._write_optsrrz, css|]}t|VqdSrMrrdr=r=r>r r4z)Option.get_help_record..zenv var: {var})varTr()css|]}t|VqdSrMrrr=r=r>r r4z (dynamic)rr z""zdefault: {default})rrrz; z [][r)#r:r3r(rrBrCr_rrrrrvr<rrErrrSrzrrrNrrQ isfunctionrrrGr Z_NumberRangeBaserrrZ_describe_rangerr)rr0rrrrrZvar_strZ resilient default_valuerZshow_default_is_strZdefault_stringZ range_strZ extra_strr=rr>r^ s              "zOption.get_help_recordrrcCsdSrMr=rr=r=r>r! szOption.get_default.cCsdSrMr=rr=r=r>r& scsR|jrB|jsB|jjD](}|j|jkr|jrtt|j SqdSt j ||dS)Nr) rrr6rr<rr3r4rErr0r)rr0rrSr2r=r>r+ s   c sTjdusJ}jr*tj|Stj|jjjjfdddS)zThis is an alternative flow that can be activated in the full value processing if a value does not exist. It will prompt the user until a valid value exists and then returns the processed value as result. Ncs |SrM)rrrr=r>rR r4z)Option.prompt_for_value..)rrGrrrZ value_proc)rrrrrGrrr)rr0rr=rr>prompt_for_value; s   zOption.prompt_for_valuecs`t|}|dur|S|jr\|jdur\|jdur\|jd|j}tj|}|r\|SdS)Nr) r0rrrvr<rrr#rrr2r=r>rU s  zOption.resolve_envvar_valuecCs^||}|durdS|jdkt|j}|dkrZ|j|}|jrZ|jdkrZt||j}|Sr)rrrdrjrGrrQ)rr0rZ value_depthr=r=r>rh s   zOption.value_from_envvarrRrcst||\}}|turJjdur<|js<|}tj}qj}tj }ntj r|durt dd|Drfdd|D}tj }n:|dtj hvrjdurj sjr|js|}tj}||fS)Ncss|]}|tuVqdSrMrrvr=r=r>r r4z'Option.consume_value..csg|]}|turjn|qSr=)rrrrr=r>r3 r4z(Option.consume_value..)r0rrrrzrrgrqrrmrjanyrorrrrr2rr>rx s8   zOption.consume_value)NNFFTFNNFFTNNFTF)T).)T)"rHrhrirjrr3rr(rrrdrr rrrrrcrrrr-rHr^rrrrrrrrgrrkr=r=r2r>rE s<   v  7' n   rEcseZdZdZdZdejeeje ej ddfdd Z e eddd Z edd d Zejee ejejeejeejefd d dZeejedddZeedddZeeddddZZS)rqaArguments are positional parameters to a command. They generally provide fewer features than options but can have infinite ``nargs`` and are required by default. All parameters are passed onwards to the constructor of :class:`Parameter`. argumentN)rrrror2c st|dur,|ddurd}n|dddk}d|vrr szArgument.__init__rcCs|jdur|jS|jSrM)rr<rrr=r=r>r s zArgument.human_readable_namecCsR|jdur|jS|j|}|s*|j}|jsr s     zArgument.make_metavarrcCsd|s|sdggfStdt|dkrD|d}}|dd}ntdt|d||ggfS)Nz8Argument is marked as exposed, but does not have a name.r rrrz6Arguments take exactly one parameter declaration, got r")rrdrr)rrrr<argr=r=r>r s   zArgument._parse_declsrcCs |gSrMrrr=r=r>r szArgument.get_usage_piecescCsd|dS)Nrrrr=r=r>r szArgument.get_error_hintrcCs|j|j|j|ddS)N)rrru) add_argumentr<rrr=r=r>rH szArgument.add_to_parser)N)rHrhrirjrr3r(rrrdrrrrrrcrrr-rrrrHrkr=r=r2r>rq s$  rq)F)N)XrkrrQrrtypingr3 collectionsr contextlibrr functoolsrrrr itertoolsrr r r exceptionsr rrrrrZ formattingrrglobalsrrrIrrrZtermuirrrutilsr r!r"r#r$r% TYPE_CHECKINGtyping_extensionsterFr'r$r)TypeVarrrr*r,rrrcr?rdrJIterablerrrQrrUr(rfEnumrgr-rr.r5rrrrRrErqr=r=r=r>s                                    (  !I?7-- 6