
    k7iN                     *   S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	J
r
JrJrJrJr  SSKJr  \(       a  SSKJr  SS	KJrJr  S
SS\S\4S jrSSS\S\S\\   4S jrS\S   S\S\\   4S jrSSS\S\S\\   4S jr    S-S\\\S4   \
4   S\\S4   S\S\S\\S4   S\\S4   S\\   4S jjrS \S\4S! jr S"\S\4S# jr!SSS\S\\   4S$ jr"SSS\S\4S% jr#S&\\S4   S'SS\S\\   4S( jr$S)\	S\4S* jr%SSS\S\4S+ jr&S'SS\S\4S, jr'g).zZsh completion script generator.

Generates static zsh completion scripts using the compsys framework.
No runtime Python dependency.
    N)dedent)indent)TYPE_CHECKING)CompletionActionCompletionDataclean_choice_textextract_completion_dataget_completion_actionstrip_markup)docstring_parse)App)ArgumentArgumentCollectionappr   	prog_namereturnc                    U(       a  [         R                  " SU5      (       d  [        SU< S35      e[        U 5      nSU 3SSU S3SS/nUR	                  [        US	UU R                  (       a  [        U R                  5      OS	U R                  (       a  [        U R                  5      OS	S
95        UR	                  SS/5        SR                  U5      S-   $ )aE  Generate zsh completion script.

Parameters
----------
app : App
    The Cyclopts application to generate completion for.
prog_name : str
    Program name (alphanumeric with hyphens/underscores).

Returns
-------
str
    Complete zsh completion script.

Raises
------
ValueError
    If prog_name contains invalid characters.
z^[a-zA-Z0-9_-]+$zInvalid prog_name: z0. Must be alphanumeric with hyphens/underscores.z	#compdef  _z() {z  local line state )r   
help_flagsversion_flags}
)
rematch
ValueErrorr	   extend_generate_completion_for_pathr   tupler   join)r   r   completion_dataliness       Q/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/completion/zsh.pygenerate_completion_scriptr%      s    ( BHH%8)DD.ym;klmm-c2O I;

I;e
E 
LL%03uS^^,B696G6G% 1 12R	
 
LL	
 99Ud""    	argumentsr   
indent_strc                     [        SU SU S35      n[        X15      nUR                  S5       Vs/ s H  oUR                  5       PM     sn$ s  snf )a  Generate dynamic completion for the 'run' command.

Parameters
----------
arguments : ArgumentCollection
    Arguments for run command.
indent_str : str
    Indentation string.
prog_name : str
    Program name.

Returns
-------
list[str]
    Zsh completion code lines.
a          local script_path
        local -a completions
        local -a remaining_words

        # If completing first argument (the script path), suggest files
        if [[ $CURRENT -eq 2 ]]; then
          _files
          return
        fi

        # Get absolute path to the script file
        script_path=${words[2]}
        script_path=${script_path:a}
        if [[ -f $script_path ]]; then
          remaining_words=(${words[3,-1]})
          local result
          local cmd

          if command -v z$ &>/dev/null; then
            cmd="a  "
          else
            return
          fi
          # Call back into cyclopts to get dynamic completions from the script
          result=$($cmd _complete run "$script_path" "${remaining_words[@]}" 2>/dev/null)
          if [[ -n $result ]]; then
            # Parse and display completion results
            completions=()
            while IFS= read -r line; do
              completions+=($line)
            done <<< $result
            _describe 'command' completions
          fi
        fir   )r   textwrap_indentsplitrstrip)r'   r(   r   templateindentedlines         r$    _generate_run_command_completionr0   P   sb    *  & # $ )" "HH x4H&.nnT&:;&:dKKM&:;;;s   Apositional_argsr   help_formatc           	         / nU  Vs/ s H  o3R                  5       (       d  M  UPM     nnU  Vs/ s H  o3R                  5       (       a  M  UPM     nnU H  nSUR                  =(       d    S-   n[        X15      nUR                  SS9nU(       a<  U V	s/ s H  n	[	        [        U	5      5      PM     n
n	SR                  U
5      nSU S3nO[        [        UR                  5      5      nU(       a  SU S	U S	U S3OSU S	U S3nUR                  U5        M     U H  n[        X15      nUR                  SS9nU(       a<  U V	s/ s H  n	[	        [        U	5      5      PM     n
n	SR                  U
5      nSU S3nO[        [        UR                  5      5      nU(       a	  S
U S	U S3OS
U S3nUR                  U5        M     U$ s  snf s  snf s  sn	f s  sn	f )a  Generate positional argument specs for nested command context.

In nested contexts (after *::arg:->args), word indexing is shifted:
- words[1] = subcommand name
- words[2] = first positional argument
- words[3] = second positional argument, etc.

Parameters
----------
positional_args : list[Argument]
    Positional arguments to generate specs for.
help_format : str
    Help text format.

Returns
-------
list[str]
    List of zsh positional argument specs.
   r   Tforce ()':'*:)is_var_positionalindex_get_description_from_argumentget_choices_escape_completion_choicer   r!   _map_completion_action_to_zshr
   hintappend)r1   r2   specsargvariadic_argsnon_variadic_argsposdescchoicescescaped_choiceschoices_stractionspecs                 r$   !_generate_nested_positional_specsrQ      s   . E %4OOS7L7L7NSOMO(7W?T?T?VW ! 399>"-c? ///-X_`X_ST89J19MNX_O`((?3KQ'F23H3RSF-33%qaxq)1SE4&9JT# !( -c?///-X_`X_ST89J19MNX_O`((?3KQ'F23H3RSF)/TF!F81%s4&]T  LM PW a as!   G	G	GGGGargumentc           	      V   / n[        X5      nU R                  SS9nU(       a  U Vs/ s H  n[        [        U5      5      PM     nnUR	                  U S35        UR	                  U S35        U H  nUR	                  U SU SU S35        M     UR	                  U S35        UR	                  U S	35        U$ [        U R                  5      n	U	[        R                  :X  a  UR	                  U S
35        U$ U	[        R                  :X  a  UR	                  U S35        U$ s  snf )a%  Generate _describe-based completion for a single positional argument.

Parameters
----------
argument : Argument
    Argument to generate completion for.
help_format : str
    Help text format.
indent_str : str
    Indentation string.

Returns
-------
list[str]
    Zsh completion code lines.
Tr5   zlocal -a choicesz	choices=(z  'r;   r:   r9   z_describe 'argument' choices_files_directories)
r?   r@   rA   r   rD   r
   rC   r   FILESDIRECTORIES)
rR   r2   r(   r#   rJ   rK   rL   rM   choicerO   s
             r$   _generate_describe_completionrY      s5   * E)(@D """.GT[\T[q45Fq5IJT[\
|#345
|9-.%FLLJ<s6(!D6;< &
|1%&
|#?@A L 'x}}5%+++LLJ<v./
 L	 '333LLJ<|45 L! ]s   D&r"   .command_pathr   r   r   c           
      z
   X   nUR                   nUR                  nSU-  n	/ n
US:X  a#  US:X  a  U
R                  [        XU5      5        U
$ / n/ nU Vs/ s H&  oR                  c  M  UR
                  (       d  M$  UPM(     nnU Vs/ s H.  oR                  5       (       a  M  UR
                  (       d  M,  UPM0     nnUR                  S S9  U H*  n[        UUR                  5      nUR                  U5        M,     [        5       nU H}  n[        S UR                   5       5      (       d  M&  [        UR                  UR                  UR                  5      nUR                  U5        UR                  UR                  5        M     U H:  nUR!                  S5      (       d  M  UU;  d  M#  S	U S
3nUR#                  U5        M<     U H:  nUR!                  S5      (       d  M  UU;  d  M#  S	U S3nUR#                  U5        M<     [        S U 5       5      nU(       aX  U(       dQ  U(       a  [%        XR                  5      nO0U H*  n['        UUR                  5      nUR#                  U5        M,     X-   nU(       a"  UR#                  S5        UR#                  S5        U(       ao  U(       a  SOSnU
R#                  U	 SU S35        USS  H  nU
R#                  U	 SU S35        M     U
R#                  U	 SUS    35        U
R#                  S5        U(       Ga  U
R#                  U	 S35        U
R#                  U	 S35        / nU Hf  nUR                   HS  nUR!                  S5      (       a  M  [)        UR                  UR                  5      nUR#                  S	U SU S	35        MU     Mh     U
R#                  U	 S35        U
R#                  U	 S35        U H  nU
R#                  U	 SU 35        M     U
R#                  U	 S35        U
R#                  U	 S35        U
R#                  U	 S35        U
R#                  U	 S35        U
R#                  U	 S 35        U H  nUR                   Hw  nUR!                  S5      (       a  M  UU4-   nUU ;   d  M)  U
R#                  U	 SU S!35        [+        U UUS"-   X4U5      nU
R                  U5        U
R#                  U	 S#35        My     M     U
R#                  U	 S$35        U
R#                  U	 S35        U
R#                  U	 S%35        U
$ s  snf s  snf )&a  Generate completion code for a specific command path.

Parameters
----------
completion_data : dict
    Extracted completion data.
command_path : tuple[str, ...]
    Command path.
indent : int
    Indentation level.
prog_name : str
    Program name.
help_flags : tuple[str, ...]
    Help flags.
version_flags : tuple[str, ...]
    Version flags.

Returns
-------
list[str]
    Zsh code lines.
r7   )runcycloptsNc                 ,    U R                   =(       d    S$ )Nr   )r>   )as    r$   <lambda>/_generate_completion_for_path.<locals>.<lambda>0  s    qww|!|r&   )keyc              3   B   #    U  H  oR                  S 5      v   M     g7f-N)
startswith).0names     r$   	<genexpr>0_generate_completion_for_path.<locals>.<genexpr>:  s     I0Hs##0Hs   re   r:   z![Display this message and exit.]'z[Display application version.]'c              3   r   #    U  H-  oR                     H  o"R                  S 5      (       + v   M     M/     g7frd   )namesrf   )rg   registered_commandcmd_names      r$   ri   rj   L  s1       ?G);XpXpH$$$Xp$xs   57z'1: :->cmds'z'*::arg:->args'z-C r   z_arguments \z  z \zcase $state inz  cmds)r;   z    local -a commandsz    commands=(z      z    )z,    _describe -t commands 'command' commandsz    ;;z  args)z    case $words[1] inr9      z
        ;;z    esacesac)commandsr'   r   r0   r>   showis_positional_onlysort_generate_keyword_specsr2   setanyrl   #_generate_keyword_specs_for_commandr   updaterf   rD   rQ   _generate_positional_spec_safe_get_description_from_appr   )r"   rZ   r   r   r   r   datars   r'   r(   r#   
args_specspositional_specsrF   r1   keyword_argsrR   rE   flag_command_namesrm   flagrP   has_non_flag_commandsc_flagcmd_listrn   rJ   cmdsub_path	sub_liness                                 r$   r   r      s   < (D}}HIvJExI$;5iYWXJ '0Vis99sSXXsiOV#,Z9C4J4J4LCQTQYQYC9LZ 34 !'$2B2BC%  !
 &I0B0H0HIII7"((*<*@*@$BRBRE e$%%&8&>&>? ' ??3D0B$Btf=>Dd# 
 ??3D0B$Btf;<Dd# 
    ?G   4@RbRbc ,04;K;KL ''- ,
 &2
.)+,/R
|;vhb9:sODLLJ<r$s34 $
|2jn%567R
|>23
|7+,"*.44**3//9:L:P:PRVRbRbcDOOaz4&$:; 5 #+ 	
|#89:
|>23CLLJ<vcU34 
|5)*
|#OPQ
|6*+
|7+,
|#89:"*.44&&s++'8+5.LLJ<vhZq!AB ='6A:yVc!I LL+LLJ<z!:; 5 #+ 	
|8,-
|6*+
|4()LO WZs$   T3)T3<T3T8$T87T8rX   c                    U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  S	S
5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U $ )aO  Escape special characters in a completion choice value for zsh.

Choice should already be cleaned via clean_choice_text() before calling this function.
This function only applies zsh-specific escaping.

Parameters
----------
choice : str
    Cleaned choice value.

Returns
-------
str
    Escaped choice value safe for zsh completion.
ro   \\r:   '\''`\`$\$"\"r7   z\ r8   z\(r9   z\)[\[]\];z\;|z\|&z\&r;   \:replace)rX   s    r$   rA   rA     s      ^^D&)F^^C)F^^C'F^^C'F^^C'F^^C'F^^C'F^^C'F^^C'F^^C'F^^C'F^^C'F^^C'F^^C'FMr&   textc                 &   U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U R                  S	S
5      n U R                  SS5      n U R                  SS5      n U R                  SS5      n U $ )zEscape special characters in description text for zsh.

Parameters
----------
text : str
    Cleaned description text.

Returns
-------
str
    Escaped description safe for zsh completion.
ro   r   r   r   r   r   r   r   r:   r   r;   r   r   r   r   r   r   )r   s    r$   _escape_zsh_descriptionr     s     <<f%D<<U#D<<U#D<<U#D<<W%D<<U#D<<U#D<<U#DKr&   c           
         / n[        X5      nU R                  5       nSnU R                  SS9nU(       a>  U Vs/ s H  n[        [	        U5      5      PM     nnSR                  U5      n	SU	 S3nSnO[        [        U R                  5      5      nU R                  R                   H  n
U
R                  S5      (       d  M  U(       a  U(       d
  S	U
 S
U S3nOAU(       a  S	U
 S
U SU
R                  S5       SU S	3	nOS	U
 S
U SU
R                  S5       S	3nUR                  U5        M     U R                   H5  n
U
R                  S5      (       d  M  S	U
 S
U S3nUR                  U5        M7     U$ s  snf )zGenerate zsh _arguments specs for a keyword argument.

Parameters
----------
argument : Argument
    Argument object from ArgumentCollection.
help_format : str
    Help text format.

Returns
-------
list[str]
    List of zsh argument specs.
r   Tr5   r7   r8   r9   Fre   r:   r   ]'z]:r;   )r?   is_flagr@   rA   r   r!   rB   r
   rC   	parameterrh   rf   lstriprD   	negatives)rR   r2   rE   rJ   r   rO   rK   rL   rM   rN   rh   rP   s               r$   rw   rw     s    E)(@DD F""".GT[\T[q45Fq5IJT[\hh/[M#./DX]]/ST ""''s##tfAdV2&DtfAdV2dkk#&6%7qBDtfAdV2dkk#&6%7q9DT ( ""s##4&$r"T # L7 ]s   E8c                    [        X5      nU R                  SS9nU(       a<  U Vs/ s H  n[        [        U5      5      PM     nnSR	                  U5      nSU S3nO[        [        U R                  5      5      nU R                  5       (       a  U(       a	  SU SU S3$ SU S3$ U R                  c  [        S	U R                   S
35      eU R                  S-   nU(       a  SU SU SU S3$ SU SU S3$ s  snf )zGenerate zsh _arguments spec for a positional argument.

Parameters
----------
argument : Argument
    Positional argument object.
help_format : str
    Help text format.

Returns
-------
str
    Zsh positional argument spec.
Tr5   r7   r8   r9   r<   r;   r:   zPositional-only argument z missing indexr4   )r?   r@   rA   r   r!   rB   r
   rC   r=   r>   r   rl   )	rR   r2   rJ   rK   rL   rM   rN   rO   rI   s	            r$   r|   r|     s    *(@D """.GT[\T[q45Fq5IJT[\hh/[M#./DX]]/ST!!##)/TF!F81%Bs4&]B ~~4X^^4DNSTT
..1
C)/Qse1TF!F81%FqQtfA5FF ]s   C8rl   cmd_appc                     / n[        X5      nU  H5  nUR                  S5      (       d  M  SU SU S3nUR                  U5        M7     U$ )a0  Generate zsh _arguments specs for a command that looks like a flag.

Parameters
----------
names : tuple[str, ...]
    Registered names for the command.
cmd_app : App
    Command app with flag-like names.
help_format : str
    Help text format.

Returns
-------
list[str]
    List of zsh argument specs.
re   r:   r   r   )r}   rf   rD   )rl   r   r2   rE   rJ   rh   rP   s          r$   rz   rz   *  sS    " E)'?D??3tfAdV2&DLL 
 Lr&   rO   c                 X    U [         R                  :X  a  gU [         R                  :X  a  gg)zMap shell-agnostic completion action to zsh-specific completion command.

Parameters
----------
action : CompletionAction
    Shell-agnostic completion action.

Returns
-------
str
    Zsh completion command (e.g., "_files", "_directories", or "").
rT   rU   r   )r   rV   rW   )rO   s    r$   rB   rB   F  s+     !'''	#//	/r&   c                 f    [        U R                  R                  =(       d    SUS9n[        U5      $ )a  Extract plain text description from Argument, escaping zsh special chars.

Parameters
----------
argument : Argument
    Argument object with parameter help text.
help_format : str
    Help text format.

Returns
-------
str
    Escaped plain text description (truncated to 80 chars).
r   format)r   r   helpr   )rR   r2   r   s      r$   r?   r?   Z  s,     **//52kJD"4((r&   c                     U R                   (       d  g [        U R                   S5      nUR                  =(       d    Sn[        X1S9n[        U5      $ ! [         a    [	        U R                   5      n N5f = f)a  Extract plain text description from App, escaping zsh special chars.

Parameters
----------
cmd_app : App
    Command app with help text.
help_format : str
    Help text format.

Returns
-------
str
    Escaped plain text description (truncated to 80 chars).
r   	plaintextr   )r   r   short_description	Exceptionstrr   r   )r   r2   parsedr   s       r$   r}   r}   m  si     <<! {;''-2 1D"4((	  !7<< !s   +A A54A5)   r]   r   r   )(__doc__r   textwrapr   r   r*   typingr   cyclopts.completion._baser   r   r   r	   r
   r   cyclopts.help.helpr   r]   r   cyclopts.argumentr   r   r   r%   listr0   rQ   rY   dictr    intr   rA   r   rw   r|   rz   rB   r?   r}   r   r&   r$   <module>r      s>   
  .    />2#E 2#c 2#c 2#j:<#:<:< :< 
#Y	:<z@*%@@ 
#Y@F,,, , 
#Y	,d "$%'T%S/>9:TS/T T 	T
 c3hT c?T 
#YTnc c B# # 03j 3s 3tCy 3l"G
 "G "G "GJuS#X  ]` eijmen 8*: s ()Z )c )c )&)E ) ) )r&   