
    lKjR              
          d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZ d dlmZmZmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z"m#Z# d dl$m%Z%m&Z&m'Z'm(Z(m)Z) erd dl*m+Z+ d dl,m-Z-m.Z. d dlm/Z/  ed      de0dz  de0fd       Z1d Z2dedz  defdZ3 e&d       G d d             Z4e G d  d!             Z5d"d#de6e7e7f   fd$Z8d"d#de6e7e7f   fd%Z9	 d:d&d'd(ee0   d)ed'   dz  fd*Z:d+ee0   de0fd,Z;d&d'de0de e#z  fd-Z<d.d/de=fd0Z> e?       d1d.d/de0d2e?e@   dee4   fd3ZAd.d/de0de4fd4ZBd5d6d"d#de0de5fd7ZCd8ede0de7e4   fd9ZDy);    N)IterableSequence)Enum)	lru_cache)Path)TYPE_CHECKINGAny
ForwardRefLiteral)defineevolvefield)resolve_annotatedis_short_flag)_get_root_module_name%_iter_resolution_argument_collections)get_field_infos)Group)
InlineText)SILENT
SilentRich)
SortHelperfrozenis_class_and_subclassresolve_callablesslice_to_str)RenderableType)ArgumentArgumentCollection)App   )maxsizedocformatc                 :   ddl }| s|j                  d      S t        j                  |       }|j	                  dd      }|d   j                  dd      }t        |      dk(  r|}n|dz   |d   z   }|j                  |      }|j                  r|j                  sJ |S )zUAddon to :func:`docstring_parser.parse` that supports multi-line `short_description`.r   N z

   
 )	docstring_parserparseinspectcleandocsplitreplacelenlong_descriptionshort_description)r$   r%   r+   cleaned_doc%short_description_and_maybe_remaindershortress          c/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/cyclopts/help/help.pydocstring_parser9       s     %%b))""3'K,7,=,=fa,H)
 2!4<<T3GE
01Q6fn'LQ'OO

 
 
-C ##s'<'<<<J    c                      ddl m}   |        S )Nr   Text)	rich.textr=   r<   s    r8   _text_factoryr?   <   s    6Mr:   valuereturnc                     | 
t               S | S N)r?   )r@   s    r8   _description_converterrD   B   s    }Lr:   T)kw_onlyc                   |   e Zd ZU dZdZeedf   ed<   	 dZeedf   ed<   	 dZ	eedf   ed<   	 dZ
eedf   ed<   	 edeedf   fd	       Zedeedf   fd
       Zedeedf   fd       ZdZeed<   	 dZeed<   	 dZeed<   	 dZedz  ed<   	 dZeedf   dz  ed<   	 dZeedf   dz  ed<   	 dZedz  ed<   	 d Zy)	HelpEntryz$Container for help table entry data. .positive_namespositive_shortsnegative_namesnegative_shortsrA   c                 4    | j                   | j                  z   S )zHAll long option names (positive + negative). For backward compatibility.)rI   rK   selfs    r8   nameszHelpEntry.namesX   s     ""T%8%888r:   c                 4    | j                   | j                  z   S )zIAll short option names (positive + negative). For backward compatibility.)rJ   rL   rN   s    r8   shortszHelpEntry.shorts]   s     ##d&:&:::r:   c                 h    | j                   | j                  z   | j                  z   | j                  z   S )z_All options in display order: positive longs, positive shorts, negative longs, negative shorts.)rI   rJ   rK   rL   rN   s    r8   all_optionszHelpEntry.all_optionsb   s2     ""T%9%99D<O<OORVRfRfffr:   NdescriptionFrequiredsort_keytypechoicesenv_vardefaultc                     t        | fi |S rC   r   rO   kwargss     r8   copyzHelpEntry.copy       d%f%%r:   )__name__
__module____qualname____doc__rI   tuplestr__annotations__rJ   rK   rL   propertyrP   rR   rT   rU   r	   rV   boolrW   rX   rY   rZ   r[   r`   rH   r:   r8   rG   rG   H   sK   .&(NE#s(O(F')OU38_)9&(NE#s(O(L')OU38_)@9uS#X 9 9 ;c3h ; ; gU38_ g g K
 Hd5Hc2D#*+&*GU38_t#*/&*GU38_t#*AGS4ZU&r:   rG   c                       e Zd ZU dZed   ed<   	 ded<   	  ede      Ze	ed<   	  ee
	      Ze
e   ed
<   	 d Zd Zd Zy)	HelpPanelz*Data container for help panel information.)command	parameterr%   r   titleN)r[   	converterrU   )factoryentriesc                     t        | fi |S rC   r]   r^   s     r8   r`   zHelpPanel.copy   ra   r:   c                     t               g }}| j                  D ]A  }|j                  |j                  f}||vs |j	                  |       |j                  |       C || _        y rC   )setrr   rP   rR   addappend)rO   seenoutitemhashables        r8   _remove_duplicateszHelpPanel._remove_duplicates   sV    E2cLLD

DKK0Ht#"

4 	 !
 r:   c                    | j                   sy| j                  dk(  rt        j                  | j                   D cg c]`  }t        |j                  |j
                  r|j
                  d   j                  d      nd|j
                  r|j
                  d   ndf|      b c}      }|D cg c]  }|j                   c}| _         yt        c c}w c c}w )zSort entries in-place.Nrm   r   -Fr'   )	rr   r%   r   sortrW   rP   
startswithr@   NotImplementedError)rO   entrysorted_sort_helperxs       r8   _sortzHelpPanel._sort   s    ||;;)#!+ "&
 ". >CkkEKKN55c:u.3kkEKKNr  ".
" .@@-?AGG-?@DL%%
 As   A%C*C)rb   rc   rd   re   r   rh   r   rD   rU   r	   listrr   rG   r`   r|   r   rH   r:   r8   rl   rl      s`    4*++@(K 
  %T2GT)_2B&&r:   rl   argument_collectionr    c                 D   g g }}| D ]  }|j                   s|j                  j                  |j                  j                  fv r|j	                  |       O|j                  j
                  sf|j                  r|j	                  |       |j	                  |        ||fS )a  Categorize keyword arguments by requirement status for usage string formatting.

    Parameters
    ----------
    argument_collection : ArgumentCollection
        Collection of arguments to categorize.

    Returns
    -------
    tuple[list, list]
        (required_keyword, optional_keyword) where:
        - required_keyword: Required keyword-only parameters
        - optional_keyword: Optional keyword-only parameters and VAR_KEYWORD
    )show
field_infokindVAR_KEYWORDrw   is_keyword_onlyrV   r   rV   optionalarguments       r8   _categorize_keyword_argumentsr      s     RhH'}}##(;(;(G(G'IIOOH%  00  )) ( Xr:   c                    g g }}| D ]  }|j                   s|j                  j                  |j                  j                  k(  r0|j                  r|j                  |       [|j                  |       m|j                  j                  s|j                  r|j                  |       |j                  |        ||fS )a  Categorize positional arguments by requirement status for usage string formatting.

    Parameters
    ----------
    argument_collection : ArgumentCollection
        Collection of arguments to categorize.

    Returns
    -------
    tuple[list, list]
        (required_positional, optional_positional) where:
        - required_positional: Required positional and VAR_POSITIONAL parameters
        - optional_positional: Optional positional and VAR_POSITIONAL parameters
    )r   r   r   VAR_POSITIONALrV   rw   is_positionalr   s       r8    _categorize_positional_argumentsr      s     RhH'}}##x':':'I'II  ))  ..  )) ( Xr:   appr!   command_chainexecution_pathc                 v    ddl m} ddlm} g }|sP j                  rD j
                  s8t        t        j                  d         j                  }|dk(  r
t               }|}n j                  d   }|j                  |       |j                  |       |D ]  } |    	 h  j                   j                  t         fd D              r|j                  d       g }	g }
g }g }t!        | d      D ]e  \  }}t#        |      \  }}t%        |      \  }}|	j                  |       |
j                  |       |j                  |       |j                  |       g |	D ]D  }|j                  } ||j&                        j)                         }|j                  | d	|        F |
r|j                  d
       |D ]  }|j*                  j,                  |j*                  j.                  k(  r>|j                  j1                  d      j)                         }|j                  | d       n|j                  j1                  d      j)                         }|j                  |        |r7t        d |D              }|r|j                  d       n|j                  d        |d	j3                  |      dz   d      S )Nr   r<   )get_hint_namez__main__.pyc              3   d   K   | ]'  }|vxr j                  |d       j                   ) yw)T)recurse_metaN)	_get_itemr   ).0r   r   help_version_flagss     r8   	<genexpr>zformat_usage.<locals>.<genexpr>  s6     
a]`XY1&&S3===+N+S+SS]`s   -0COMMANDF)fallback_appparse_docstringr*   z	[OPTIONS]r~   z...c              3   v   K   | ]1  }|j                   j                  |j                   j                  k(   3 y wrC   )r   r   r   )r   args     r8   r   zformat_usage.<locals>.<genexpr>C  s.      !
LdSCNN3>>#@#@@Lds   79z	[ARGS...]z[ARGS]r)   bold)style)r>   r=   cyclopts.annotationsr   default_command_namer   sysargvnamer   rw   extend
help_flagsversion_flagsanyr   r   r   hintupperr   r   r   lstripjoin)r   r   r   r=   r   usager   app_namerm   required_keyword_paramsoptional_keyword_paramsrequired_positional_argsoptional_positional_args_r   rkwokwrposoposr   
param_name	type_namearg_namehas_var_positionalr   s   `                       @r8   format_usager      sx   
 2E S00CHHQK %%= (*D88A;	LL	LL 'l ! ?3>>>C,=,=>

a]`
aaY
 %'$&%'%'"GS%# 11DES56IJ
d&&s+&&s+ ''- ''-# ,]]
!(--0668	
|1YK01 ,
 [!,##x':':'I'II}}++C0668HLLH:S)*}}++C0668HLL" -    !
Ld!
 
 LL%LL"$&f55r:   stringsc                     | sy| d   g}| dd D ]<  }|d   j                  d      r|j                  |       )|j                  d|z          > dj                  |      S )zJJoins strings with a space, unless the previous string ended in a newline.r'   r   r(   Nr)   r*   )endswithrw   r   )r   resultss      r8   _smart_joinr   N  sa    aj\FQR[":t$MM!MM#'"	  776?r:   c                 j   | j                   }|st        S t        ||      }g }|j                  r|j	                  |j                  dz          |j
                  r;|j                  r|j	                  d       |j	                  |j
                  dz          t        j                  t        |      |d      S )Nr)   Tr%   force_empty_end)	helpr   r9   r3   rw   r2   r   from_formatr   )r   r%   raw_doc_stringparsed
componentss        r8   
format_docr   ]  s    XXN^V4FJ&22T9:##d#&11D89!!+j"9&Z^__r:   r   r   c                     | j                   }| j                  r| j                  s|yt        |t        t
        f      ry	 t        t        |            S # t        $ r Y yw xY w)u  True if ``argument`` is ``dict[str, StructuredType]`` eligible for help expansion.

    Covers pydantic, dataclass, attrs, TypedDict, NamedTuple via the shared
    ``get_field_infos`` dispatcher.  Uses the same indicators as the parser's
    dict branch in ``Argument.__attrs_post_init__``: ``_accepts_keywords`` is
    set, ``_lookup`` is empty (no pre-built children — keys are dynamic), and
    ``_default`` is the value type with structured fields.

    Also matches when ``_default`` is a string/``ForwardRef`` — an unresolved
    self-reference from something like ``dict[str, "Node"]``.  We can't walk
    into it, but we treat it as assumed-structured so the expansion still
    renders a ``.{NAME}`` layer before terminating.
    FT)	_default_accepts_keywords_lookup
isinstancerg   r
   rj   r   	Exception)r   r[   s     r8   _is_dynamic_structured_dictr   p  sa     G&&x/?/?GDW'C,-OG,-- s    A 	A A rx   rx   c          
   #   $  K   ddl m} ddlm} ddlm} | j                  }t        | j                        t        fd| j                  D              }t        |t        t        f      }t        |      |v }	|	s|s|s?t        | |      }
|r,t        d |
j                   D              }t#        |
|       y|
 y|t        |      hz  } |d	|j$                  ||j&                  | j(                  
      }|D ]  } |j*                  |d || df      i t-        j.                         t-        j0                         d      }|j3                  d      D ]2  }t5        |      rt7        |||      E d{    %t        ||       4  y7 w)aW  Yield help entries for every leaf field of a ``dict[str, StructuredType]``.

    Reuses :meth:`ArgumentCollection._from_type_preview` so synthesized entries
    carry the full metadata (choices, defaults, env_var, required propagation,
    ``Parameter.help`` precedence, ``name_transform``) that the normal
    per-argument path produces.
    r   )r    )	FieldInfo)	Parameterc              3   D   K   | ]  }|vst        |      r|  y wrC   r   )r   o	negativess     r8   r   z3_expand_structured_dict_for_help.<locals>.<genexpr>  s"     f1!9:LUbcdUeQs   	   c              3   &   K   | ]	  }| d   yw).{NAME}NrH   )r   ns     r8   r   z3_expand_structured_dict_for_help.<locals>.<genexpr>  s     "P<OqaS	?<Os   )rI   N)_preview)rP   r   
annotationr[   rV   rH   r   )r   F)group_lookupgroup_argumentsgroup_parameters_resolve_groupsTr   r   )cyclopts.argumentr    cyclopts.field_infor   cyclopts.parameterr   r   ru   r   rf   rP   r   rg   r
   id_make_help_entryrI   r   KEYWORD_ONLYemptyrV   
_from_typer   create_default_argumentscreate_default_parameters	filter_byr    _expand_structured_dict_for_help)r   r%   rx   r    r   r   
value_typeouter_long_namesis_unresolvableis_cyclebasesuffixed_namesnew_seen	syntheticouterpreviewleafr   s                    @r8   r   r     s    " 5-,""JH&&'Ifff c:->?O*~%H?*:  &1""PD<O<O"PPNn== 	 Jr*~&&H##""I "/$//ugY/12!::<"<<>!
 %%4%0D*40;D&xXXX&tV44	 1 " Ys   E2F5F6Fc                    | j                   j                  sJ t        | j                        }t	               }|D cg c]  }||vs|j                  |      r| }}| j                  Bt        d |D        |d         }|j                  d      j                         }||d   k7  r|g|}t	        | j                        }|D cg c]  }||vst        |      r| }	}|D cg c]  }||vst        |      s| }
}|D cg c]  }||v st        |      r| }}|D cg c]  }||v st        |      s| }}t        j                  | j                   j                  |      }| j                         }d}| j                   j                   r5| j                   j"                  rt%        | j                   j"                        }d}t'        | j(                  t*              r| j(                  }n| j(                  r| j,                  j.                  }t1        | j2                  t4              r'| j                   j                  |j6                        }n`t'        |t        t$        t        t8        f      rg }|D ]  }t'        |t4              r5|j;                  | j                   j                  |j6                               Ht'        |t*              r|j;                  d| d       n|j;                  t+        |              t'        |t$              r2t=        |      dk(  rd|d   z   d	z   }ndd
j?                  |      z   dz   }not'        |t              rdd
j?                  |      z   dz   }nGdd
j?                  |      z   dz   }n/t'        |t@              rtC        |      }n|dk(  rd}nt+        |      }tE        | j(                        r| j)                  |      }tG        t%        |	      t%        |
      t%        |      t%        |      || jH                  tK        | j,                  jL                        |||
      S c c}w c c}w c c}w c c}w c c}w )zBuild a single ``HelpEntry`` for one ``Argument``.

    Extracted from ``create_parameter_help_panel`` so it can also be applied
    to synthetic preview arguments (see ``_expand_structured_dict_for_help``).
    Nc              3   D   K   | ]  }|j                  d       s|  yw)z--N)r   )r   r   s     r8   r   z#_make_help_entry.<locals>.<genexpr>  s     F11<<3EQs     r   r~   r%   'r(   (z,)z, )[]{}r'   z"")
rI   rJ   rK   rL   rU   rV   rX   rY   rZ   r[   )'rn   name_transformr   rP   ru   rv   indexnextr   r   r   r   r   r   r   get_choicesshow_env_varrZ   rf   r   show_defaultrg   r   r[   r   r   r   r   	frozensetrw   r1   r   slicer   callablerG   rV   r   r   )r   r%   optionsrx   r   label_sourcer   r   r   rI   rJ   rK   rL   help_descriptionrY   rZ   r[   default_valformatted_itemsrz   s                       r8   r   r     s    ,,,,8>>"GUD!G'QQd]488A;q'GG~~!FFPQ
S&&s+113wqz!*'*GH&&'I!(XAAY,>}UVGWaNX")U'QQi-?MRSDTq'OU!(TAAN=QRCSaNT")Q'QQ)^a@Pq'OQ!--h.@.@.E.EfU""$GG&&8+=+=+E+E**223G(''-''			))11 5((778H8HIGdE3	%BC O#dD)#**8+=+=+L+LTYY+WXc*#**QtfA;7#**3t95 $ +u-'1,!OA$66=G!DIIo$>>DGK.		/ ::S@		/ ::S@U+";/GBG+&GH))*++K8G^,o.^,o.$""x22==> q H YUTQsY   	P=P=P=	QQQ%	Q/Q;Q	QQQ%	Q/Q;Qgroupr   c                 (   ddl m} d| j                  | j                  r"t	        j
                  | j                  |d      n |       d}t        di |}g g }}|j                  d      D ]n  }t        |      r|j                  t        ||             *t        ||      }	|j                  j                  r|j                  |	       ^|j                  |	       p |j                  j                  |       |j                  j                  |       |S )	Nr   r<   rn   Tr   )r%   ro   rU   r   rH   )r>   r=   r   r   r   r   rl   r   r   r   r   r   r   r   rw   rr   )
r  r   r%   r=   r_   
help_panelentries_positional
entries_kwr   r   s
             r8   create_parameter_help_panelr"    s    
  :: "--ejjY]^VF $V$J%'
'11t1<&x0>xPQ 62,,%%e,e$ = 01j)r:   apps_with_namesc                    g }| D ]  }|j                   }|j                  s|j                  }g g }}|D ]/  }t        |      r|j	                  |      n|j	                  |       1 t        |j                  |      }	t        t        |      t        |      t        j                  t        |j                  |      j                  |      |	      }
|
|vs|j	                  |
        |S )a,  Format command entries for help display.

    Parameters
    ----------
    apps_with_names : Iterable[RegisteredCommand]
        Iterable of RegisteredCommand tuples.
    format : str
        Help text format.

    Returns
    -------
    list[HelpEntry]
        List of formatted help entries.
    r  )rI   rJ   rU   rW   )r   r   rP   r   rw   r   rW   rG   rf   r   r   r9   r   r3   )r#  r%   rr   registered_commandr   rP   short_names
long_namesr   rW   r   s              r8   format_command_entriesr(  >  s     G- $$xx"(("$bZD(5d(;Kt$ARARSWAX  %S\\37 ,!+."..sxx/P/b/bkqr	
 NN5!' .( Nr:   rC   )Er-   r   collections.abcr   r   enumr   	functoolsr   pathlibr   typingr   r	   r
   r   attrsr   r   r   r   r   cyclopts.argument.utilsr   cyclopts.corer   r   r   r   cyclopts.groupr   cyclopts.help.inline_textr   cyclopts.help.silentr   r   cyclopts.utilsr   r   r   r   r   rich.consoler   r   r   r    r!   rg   r9   r?   rD   rG   rl   rf   r   r   r   r   r   r   rj   r   r  intr   r   r"  r(  rH   r:   r8   <module>r7     s8    
 .     ( ' 2 1 V /   0 3 e e+>! 2t S  6#*   7& 7& 7&t 6& 6& 6&r7K PUVZ\`V`Pa @ :N  SXY]_cYcSd  L .2K6	K6C=K6 UOd*K6\# 3 `E `3 `:
+B `&*  : %;	?5?5?5 C.	?5
 i?5DNz N3 N9 Nb-  	D$H $c $d9o $r:   