o
    VÌh°#  ã                   @  s4  d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d d	lmZ d d
lmZ d dlmZ d dlmZ erd dlZejdkrZd dlmZ nd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z% d dl$m&Z& G dd„ de	ƒZ'dS )é    )Úannotations)ÚTYPE_CHECKING)ÚAny)ÚClassVar)ÚContextManager)Úcast)ÚBaseCommand)ÚStyle)ÚStringInput)ÚNullIO)Ú	Verbosity©ÚTableSeparatorN)é   é   )ÚLiteral)ÚArgument)ÚOption)ÚIO©ÚProgressBar©ÚProgressIndicator©ÚQuestion)ÚRows©ÚTablec                      s¼  e Zd ZU g Zded< g Zded< g Zded< g Zded< g Zded	< dw‡ fdd„Z	e
dxdd„ƒZdwdd„Zdydd„Zdzdd„Zd{d|dd„Zd{d|d d!„Zd}d#d$„Zd}d%d&„Z	(d~dd-d.„Zd{d€d1d2„Zd{d€d3d4„Z			'dd‚d:d;„Z	d{dƒd@dA„Z			d„d…dGdH„Zd†dJdK„Zd{d‡dNdO„Zd{dˆdQdR„Zdejfd‰dUdV„Zdejfd‰dWdX„ZdŠdYdZ„Z dŠd[d\„Z!dŠd]d^„Z"d‹dŒdbdc„Z#		d	ddŽdjdk„Z$		d	dddodp„Z%			d„ddsdt„Z&dŠdudv„Z'‡  Z(S )‘ÚCommandzClassVar[list[Argument]]Ú	argumentszClassVar[list[Option]]ÚoptionszClassVar[list[str]]ÚaliasesÚusageszClassVar[list[BaseCommand]]ÚcommandsÚreturnÚNonec                   s   d | _ tƒ  ¡  d S ©N)Ú_ioÚsuperÚ__init__©Úself©Ú	__class__© úi/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/cleo/commands/command.pyr)   *   s   zCommand.__init__r   c                 C  s   | j S r&   )r'   r*   r.   r.   r/   Úio.   s   z
Command.ioc                 C  s4   | j D ]}| j |¡ q| jD ]}| j |¡ qd S r&   )r   Ú_definitionÚadd_argumentr    Ú
add_option)r+   ÚargumentÚoptionr.   r.   r/   Ú	configure2   s
   

ÿzCommand.configurer0   Úintc                 C  s&   || _ z|  ¡ W S  ty   Y dS w )Né   )r'   ÚhandleÚKeyboardInterrupt)r+   r0   r.   r.   r/   Úexecute9   s   
ÿzCommand.executec                 C  s   t ‚)z&
        Execute the command.
        )ÚNotImplementedErrorr*   r.   r.   r/   r9   A   s   zCommand.handleNÚnameÚstrÚargsú
str | Nonec                 C  s8   | j dusJ ‚| j  |¡}| j  || j t|pdƒ¡¡S )z'
        Call another command.
        NÚ )ÚapplicationÚgetÚ_run_commandr'   Ú
with_inputr
   ©r+   r=   r?   Úcommandr.   r.   r/   ÚcallG   s
   ÿzCommand.callc                 C  s4   | j dusJ ‚| j  |¡}| j  |tt|pdƒƒ¡S )z0
        Call another command silently.
        NrA   )rB   rC   rD   r   r
   rF   r.   r.   r/   Úcall_silentR   s   zCommand.call_silentr   c                 C  ó   | j j |¡S )z6
        Get the value of a command argument.
        )r'   Úinputr4   ©r+   r=   r.   r.   r/   r4   [   ó   zCommand.argumentc                 C  rJ   )z4
        Get the value of a command option.
        )r'   rK   r5   rL   r.   r.   r/   r5   a   rM   zCommand.optionFú(?i)^yÚquestionÚdefaultÚboolÚtrue_answer_regexc                 C  s,   ddl m} ||||d}tt| | j¡ƒS )z3
        Confirm a question with the user.
        r   ©ÚConfirmationQuestion)rP   rR   )Úcleo.ui.confirmation_questionrT   r   rQ   Úaskr'   )r+   rO   rP   rR   rT   Úconfirmationr.   r.   r/   Úconfirmg   s
   ÿzCommand.confirmústr | Questionú
Any | Nonec                 C  s.   ddl m} t||ƒs|||d}| | j¡S )z,
        Prompt the user for input.
        r   r   ©rP   )Úcleo.ui.questionr   Ú
isinstancerV   r'   ©r+   rO   rP   r   r.   r.   r/   rV   t   s   
zCommand.askc                 C  s6   ddl m} t||ƒs|||d}| ¡  | | j¡S )zQ
        Prompt the user for input but hide the answer from the console.
        r   r   r[   )r\   r   r]   ÚhiderV   r'   r^   r.   r.   r/   Úsecret   s
   
zCommand.secretÚchoicesú	list[str]Úattemptsú
int | NoneÚmultiplec                 C  s8   ddl m} ||||ƒ}| |¡ | |¡ | | j¡S )zH
        Give the user a single choice from an list of answers.
        r   ©ÚChoiceQuestion)Úcleo.ui.choice_questionrg   Úset_max_attemptsÚset_multi_selectrV   r'   )r+   rO   ra   rP   rc   re   rg   Úchoicer.   r.   r/   rk   Œ   s
   

zCommand.choiceÚtypeú(Literal['choice', 'confirmation'] | NoneÚkwargsr   c                 K  sd   ddl m} ddlm} ddlm} |dkr||fi |¤ŽS |dkr*||fi |¤ŽS ||fi |¤ŽS )z7
        Returns a Question of specified type.
        r   rf   rS   r   rW   rk   )rh   rg   rU   rT   r\   r   )r+   rO   rl   rn   rg   rT   r   r.   r.   r/   Úcreate_question    s   	zCommand.create_questionÚheaderÚrowsúRows | NoneÚstyler   c                 C  s<   ddl m} || j|d}|r| |g¡ |r| |¡ |S )z*
        Return a Table instance.
        r   r   )rs   )Úcleo.ui.tabler   r'   Úset_headersÚset_rows)r+   rp   rq   rs   r   Útabler.   r.   r/   rw   µ   s   	
zCommand.tabler   c                 C  s   t ƒ S )z3
        Return a TableSeparator instance.
        r   r*   r.   r.   r/   Útable_separatorÊ   s   zCommand.table_separatorÚheadersr   c                 C  s   |   |||¡}| ¡  dS )z0
        Format input to textual table.
        N)rw   Úrender)r+   ry   rq   rs   rw   r.   r.   r/   Úrender_tableÑ   s   zCommand.render_tableÚtextc                 C  s*   |rd|› d|› dn|}| j  |¡ dS )zd
        Writes a string without a new line.
        Useful if you want to use overwrite().
        ú<ú>ú</>N)r'   Úwrite)r+   r|   rs   Ústyledr.   r.   r/   r€   Ù   s   zCommand.writeÚ	verbosityr   c                 C  s.   |rd|› d|› dn|}| j j||d dS )z7
        Write a string as information output.
        r}   r~   r   )r‚   N)r'   Ú
write_line©r+   r|   rs   r‚   r   r.   r.   r/   Úlineâ   s   	zCommand.linec                 C  s,   |rd|› d|› dn|}| j  ||¡ dS )zA
        Write a string as information output to stderr.
        r}   r~   r   N)r'   Úwrite_error_liner„   r.   r.   r/   Ú
line_errorï   s   	zCommand.line_errorc                 C  ó   |   |d¡ dS )zw
        Write a string as information output.

        :param text: The line to write
        :type text: str
        ÚinfoN©r…   ©r+   r|   r.   r.   r/   r‰   ü   ó   zCommand.infoc                 C  rˆ   )zs
        Write a string as comment output.

        :param text: The line to write
        :type text: str
        ÚcommentNrŠ   r‹   r.   r.   r/   r     rŒ   zCommand.commentc                 C  rˆ   )zt
        Write a string as question output.

        :param text: The line to write
        :type text: str
        rO   NrŠ   r‹   r.   r.   r/   rO     rŒ   zCommand.questionr   Úmaxr   c                 C  s   ddl m} || j|dS )z,
        Creates a new progress bar
        r   r   )rŽ   )Úcleo.ui.progress_barr   r'   )r+   rŽ   r   r.   r.   r/   Úprogress_bar  s   zCommand.progress_baréd   ÚfmtÚintervalÚvaluesúlist[str] | Noner   c                 C  s   ddl m} || j|||ƒS )z3
        Creates a new progress indicator.
        r   r   )Úcleo.ui.progress_indicatorr   r0   )r+   r’   r“   r”   r   r.   r.   r/   Úprogress_indicator  s   	zCommand.progress_indicatorÚstart_messageÚend_messageú!ContextManager[ProgressIndicator]c                 C  s   |   |||¡}| ||¡S )z:
        Automatically spin a progress indicator.
        )r—   Úauto)r+   r˜   r™   r’   r“   r”   Úspinnerr.   r.   r/   Úspin,  s   zCommand.spinÚfgÚbgc                 C  s4   t |||ƒ}| jjj ||¡ | jjj ||¡ dS )z"
        Adds a new style
        N)r	   r'   ÚoutputÚ	formatterÚ	set_styleÚerror_output)r+   r=   rž   rŸ   r    rs   r.   r.   r/   Ú	add_style;  s   
zCommand.add_stylec                 C  s   | j  |¡ dS )zx
        Overwrites the current line.

        It will not add a new line so use line('')
        if necessary.
        N)r'   Ú	overwriter‹   r.   r.   r/   r¥   I  rŒ   zCommand.overwrite)r$   r%   )r$   r   )r0   r   r$   r7   )r$   r7   r&   )r=   r>   r?   r@   r$   r7   )r=   r>   r$   r   )FrN   )rO   r>   rP   rQ   rR   r>   r$   rQ   )rO   rY   rP   rZ   r$   r   )NNF)rO   r>   ra   rb   rP   rZ   rc   rd   re   rQ   r$   r   )rO   r>   rl   rm   rn   r   r$   r   )NNN)rp   r@   rq   rr   rs   r@   r$   r   )r$   r   )ry   r>   rq   r   rs   r@   r$   r%   )r|   r>   rs   r@   r$   r%   )r|   r>   rs   r@   r‚   r   r$   r%   )r|   r>   r$   r%   )r   )rŽ   r7   r$   r   )Nr‘   N)r’   r@   r“   r7   r”   r•   r$   r   )r˜   r>   r™   r>   r’   r@   r“   r7   r”   r•   r$   rš   )
r=   r>   rž   r@   rŸ   r@   r    r•   r$   r%   ))Ú__name__Ú
__module__Ú__qualname__r   Ú__annotations__r    r!   r"   r#   r)   Úpropertyr0   r6   r;   r9   rH   rI   r4   r5   rX   rV   r`   rk   ro   rw   rx   r{   r€   r   ÚNORMALr…   r‡   r‰   r   rO   r   r—   r   r¤   r¥   Ú__classcell__r.   r.   r,   r/   r   #   sp   
 



	
ÿúýü
üü

	
		
üúûr   )(Ú
__future__r   Útypingr   r   r   r   r   Úcleo.commands.base_commandr   Úcleo.formatters.styler	   Úcleo.io.inputs.string_inputr
   Úcleo.io.null_ior   Úcleo.io.outputs.outputr   Úcleo.ui.table_separatorr   ÚsysÚversion_infor   Útyping_extensionsÚcleo.io.inputs.argumentr   Úcleo.io.inputs.optionr   Ú
cleo.io.ior   r   r   r–   r   r\   r   rt   r   r   r   r.   r.   r.   r/   Ú<module>   s4    
