
    辙h                        d dl Z d dlZd dlZd dlZd dlmZ ddlmZmZ g dZ	ej                  dk\  r	d dlmZmZ nd dlmZmZ ddZi Zdd	Zdd
ZddZd Zd Z eg ded        eg ded       	 	 ddZd Zd Zd Zy)    N)defaultdict   )CommandLineParserErrorExitReplException)
_execute_internal_and_sys_cmds_exit_internal_get_registered_target_help_internal_resolve_context_register_internal_commanddispatch_repl_commandshandle_internal_commandssplit_arg_stringexit)   r   )IterableMappingc                    | r|j                   }t        |t        j                        r|j                  sI|j                  ||       \  }}} ||S |j                  || |d      }|j                  |j                  z   } nb| r@|j                  ||       \  }}} ||S |j                  || |ddd      }|j                  } | r@}g |j                  |j                  } n	 |S | r|S )a;  Produce the context hierarchy starting with the command and
    traversing the complete arguments. This only follows the commands,
    it doesn't trigger input prompts or callbacks.

    :param args: List of complete args before the incomplete value.
    :param cli_ctx: `click.Context` object of the CLI group
    T)parentresilient_parsingF)r   allow_extra_argsallow_interspersed_argsr   )	command
isinstanceclickMultiCommandchainresolve_commandmake_contextprotected_argsargs)r!   ctxr   namecmdsub_ctxs         L/var/www/Befach/backend/env/lib/python3.12/site-packages/click_repl/utils.pyr   r       s	    ++gu112==")"9"9#t"Dc4;J&&tT#QU&V))CHH4&-&=&=c4&HOD#t{"
!..")-05*. / G #<<D   ?//?',,?JE D J    c                     t        j                   | |      }d|_        d|_        g }	 |D ]  }|j                  |        	 |S # t        $ r |j                  |j
                         Y |S w xY w)a  Split an argument string as with :func:`shlex.split`, but don't
    fail if the string is incomplete. Ignores a missing closing quote or
    incomplete escape sequence and uses the partial token as-is.
    .. code-block:: python
        split_arg_string("example 'my file")
        ["example", "my file"]
        split_arg_string("example my\")
        ["example", "my"]
    :param string: String to split.
    )posixT )shlexwhitespace_split
commentersappend
ValueErrortoken)stringr)   lexoutr0   s        r&   r   r   Q   sr     ++fE
*CCCN
CEJJu  J   	

399Js   A $A,+A,c                    t        |d      st        d      t        | t              r| g} nMt        | t              st        | t
              s-t        dj                  t        |       j                              | D ]  }||ft        |<    y )N__call__z#Internal command must be a callablez="names" must be a string, or an iterable object, but got "{}")
hasattrr/   r   strr   r   formattype__name___internal_commands)namestargetdescriptionr#   s       r&   r   r   n   s    6:&>??%	E7	#:eX+FKRRU$$
 	
 $*K#84  r'   c                 >    t         j                  |       }|r|d   S |S )Nr   )r;   get)r#   defaulttarget_infos      r&   r	   r	      s$    $((.K1~Nr'   c                      t               N)r    r'   r&   r   r      s    

r'   c                  <   t        j                         } | j                  d       | j                          | j	                  d      5  | j                  d       d d d        | j	                  d      5  | j                  d       t        t              }t        j                         D ]  \  }}||d      j                  |        | j                  d |j                         D               d d d        | j                         }|S # 1 sw Y   xY w# 1 sw Y   'xY w)Nz	REPL helpzExternal Commandsz!prefix external commands with "!"zInternal Commandsz!prefix internal commands with ":"r   c           	   3      K   | ]7  \  }}d j                  t        dj                  t        |                  |f 9 yw)z, z:{}N)joinmapr8   sorted).0r>   	mnemonicss      r&   	<genexpr>z!_help_internal.<locals>.<genexpr>   s?      

 'Y 		#ellF9,=>?
s   =?)r   HelpFormatterwrite_headingindentsection
write_textr   listr;   itemsr.   write_dlgetvalue)	formatter
info_tablemnemonicrB   vals        r&   r
   r
      s   ##%IK(			.	/ B@AB 
		.	/ 
@A &
%7%=%=%?!Hk{1~&--h7 &@ 	 

 +5*:*:*<
 	

 


CJ'B B
 
s   D2A:DDD)qquitr   zexits the repl)?hhelpz!displays general help informationc                     |rt        |       ry|r1t        |       }t        |t              rt	        j
                  |       y	 t        |       S # t        $ r}t        dj                  |            d}~ww xY w)z_
    Executes internal, system, and all the other registered click commands from the input
    Nz{})
r   r   r   r7   r   echor   r/   r   r8   )r   allow_internal_commandsallow_system_commandsresultes        r&   r   r      sk     !7!@)'2fc"JJv5(( 5$T[[^445s   
A 	A6A11A6c                      t                y)zExit the replN)r   rE   r'   r&   r   r      s    r'   c                 X    | j                  d      rt        j                  | dd        yy)zo
    Execute system commands entered in the repl.

    System commands are all commands starting with "!".
    !r   NTF)
startswithossystem)r   s    r&   r   r      s*     #
		'!"+r'   c                 Z    | j                  d      rt        | dd d      }|r |       S yy)ze
    Run repl-internal commands.

    Repl-internal commands are all commands starting with ":".
    :r   N)rA   )ri   r	   )r   r=   s     r&   r   r      s8     #'TB8O  r'   rD   )T)TT)r   rj   r+   syscollectionsr   
exceptionsr   r   __all__version_infocollections.abcr   r   r   r;   r   r   r	   r   r
   r   r   r   r   rE   r'   r&   <module>rt      s     	  
 # A  v11-+\  :9$6 0.BR S (K !5.

	r'   