
    k7iA                     V   S r SSKJr  SSKJr  SSKJr  SSKJr  \(       a  SSK	J
r
    S#S\\   S-  S	\\   S-  S
\\\   S-  \\   S-  4   4S jjrS\S\\   S\\   S-  S\\   S-  SSS
\4S jrS\S\\   S-  S\\   S-  S
\\\   S-  \\   S-  4   4S jr     S$SSS\S\S\\   S-  S	\\   S-  S\\   S-  S
\\\\S4      4S jjr S%S\\   S\\\\S4      S\S-  S
S4S jjr         S&SSS\S\S\S\\   S-  S\S \S\\   S-  S	\\   S-  S!\S
\4S" jjrg)'z9RST documentation generation functions for cyclopts apps.    )TYPE_CHECKING)extract_text)BaseDocGenerator)make_rst_section_header)AppNcommands_filterexclude_commandsreturnc                     SnU b!  U  Vs1 s H  o3R                  SS5      iM     nnSnU(       a!  U Vs1 s H  o3R                  SS5      iM     nnX$4$ s  snf s  snf )ab  Normalize command filter lists by converting underscores to dashes.

Parameters
----------
commands_filter : Optional[List[str]]
    List of commands to include.
exclude_commands : Optional[List[str]]
    List of commands to exclude.

Returns
-------
Tuple[Optional[Set[str]], Optional[Set[str]]]
    Normalized include and exclude sets for O(1) lookup.
N_-)replace)r   r	   normalized_includecmdnormalized_excludes        K/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/docs/rst.py_normalize_command_filtersr      sl    $ "?NOkk#s3O?OP?Okk#s3?OP11 P Qs
   AAnameparent_pathnormalized_commands_filternormalized_exclude_commandssubappr   c                 
   U(       a  SR                  X/-   5      OU nU(       aD  X;   d  XS;   a  g[        [        U5      5       H!  nSR                  USUS-    5      nXs;   d  M!    g   Ub  X;   d  XR;   a  g[        [        U5      5       H!  nSR                  USUS-    5      nXr;   d  M!    g   U(       d  X;   a  g[        US5      (       a5  UR                  (       a$  U H  nUR                  US-   5      (       d  M    g   gg)a  Determine if a command should be included based on filters.

Parameters
----------
name : str
    The command name.
parent_path : List[str]
    Path to parent commands.
normalized_commands_filter : Optional[Set[str]]
    Set of commands to include (already normalized).
normalized_exclude_commands : Optional[Set[str]]
    Set of commands to exclude (already normalized).
subapp : App
    The subcommand App instance.

Returns
-------
bool
    True if the command should be included, False otherwise.
.FN   T	_commands)joinrangelenhasattrr   
startswith)	r   r   r   r   r   	full_pathiparent_segment
filter_cmds	            r   _should_include_commandr&   *   s    6 3>v-.4I".)2Zs;'(A XXk'AE&:;N< )
 "--1Xs;'(A XXk'AE&:;N; )
 tA6;''F,<,<8
((S99 9     c                    SnUbi  / nU HY  nUR                  U S-   5      (       a4  U[        U 5      S-   S nUR                  UR                  SS5      5        MP  X@:X  d  MW  Sn  O   U/ :X  a  / nSnU(       ay  / nU Hq  nUR                  U S-   5      (       a4  U[        U 5      S-   S nUR                  UR                  SS5      5        MP  UR                  UR                  SS5      5        Ms     X64$ )a  Adjust filter lists for subcommand context.

Parameters
----------
name : str
    The current command name.
normalized_commands_filter : Optional[Set[str]]
    Set of commands to include (already normalized).
normalized_exclude_commands : Optional[Set[str]]
    Set of commands to exclude (already normalized).

Returns
-------
Tuple[Optional[List[str]], Optional[List[str]]]
    Adjusted commands_filter and exclude_commands lists (denormalized).
Nr   r   r   r   )r!   r   appendr   )	r   r   r   sub_commands_filterr%   
sub_filtersub_exclude_commandsexclude_cmdsub_excludes	            r   _adjust_filters_for_subcommandr/   e   s   * !- 4J$$TCZ00'D	A8
#**:+=+=c3+GH#&*# 5 "$"$"!6K%%dSj11)#d)a-/:$++K,?,?S,IJ$++K,?,?S,IJ 7 44r'   appinclude_hiddenprefixc           
         / nU R                   (       d  U$ Uc  / n[        X45      u  px[        R                  " X5       H  u  p[	        XXxU
5      (       d  M  U(       a  U U	 3OU	nUR                  SS5      R                  5       nUR                  XU
45        XY/-   n[        U
UU S3UUUS9nUR                  U5        M     U$ )zoRecursively collect all commands for table of contents.

Returns a list of (display_name, anchor, app) tuples.
 r   )r1   r2   r   r	   r   )
r   r   r   iterate_commandsr&   r   lowerr)   _collect_commands_for_tocextend)r0   r1   r2   r   r	   r   commandsr   r   r   r   display_nameanchornested_pathnesteds                  r   r7   r7      s     H==>X?;
 )99#N&9X^
 
 ,2&$(%%c3/557v67!F**)"^1%+-#
 	+ O. Or'   linesr9   app_namec                     U(       d  gU R                  S5        U R                  S5        U R                  S5        U R                  S5        g)z5Generate TOC entries with proper indentation for RST.Nz.. contents:: Commandsz
   :local:z   :depth: 2 )r)   )r>   r9   r?   s      r   _generate_toc_entriesrB      s;     	LL)*	LL	LL 	LLr'   	recursiveheading_levelcommand_chaingenerate_tocflatten_commandsno_root_titlec
                    SSK Jn
  / nUc  / n[        R                  " X5      u  pnU(       a)  [	        U5      S:  a  SR                  USS 5      OUS   nOUnS/nU(       a  UR                  U5        OUR                  U5        SR                  U5      R                  SS5      R                  S	S5      R                  5       nUR                  S
U S35        UR                  S5        U	(       a
  U(       d  UnO+U(       a
  U(       a  UnOU(       a  U[	        U5      -   S-
  OUnU	(       a  U(       a.  [        UU5      nUR                  U5        UR                  S5        U R                  R                  SSS9n[        R                  " U U5      nU(       aG  US;   n[        USUS9nU(       a0  UR                  UR                  5       5        UR                  S5        U	(       a  U(       a)  U(       a"  UR                  S5        UR                  S5        U	(       a  U(       a  [        R                   " U 5      nSnU(       ak  [#        U[$        5      (       a  UnO[        USSS9nU(       a  [        R&                  " UUSS9nSU;   a   UR                  SS5      R                  5       nSU 3nU(       a_  UR                  S5        UR                  S5        UR)                  S5       H  nUR                  SU 35        M     UR                  S5        U R+                  / U5      nU
" US-   US9n[        R,                  " UU5      nUS   nUS   nUS   n U(       a  U	(       a  U(       a  UR                  S5        UR                  S5        U Hp  u  n!n"UR/                  5         SU"l        U" SSU"5        UR3                  5       R                  5       n#U#(       d  MN  UR                  U#5        UR                  S5        Mr     U(       d  U (       Ga  U	(       a  U(       Ga  UR                  S5        UR                  S5        U Hp  u  n!n"UR/                  5         SU"l        U" SSU"5        UR3                  5       R                  5       n#U#(       d  MN  UR                  U#5        UR                  S5        Mr     U  Hi  u  n!n"UR/                  5         U" SSU"5        UR3                  5       R                  5       n#U#(       d  MG  UR                  U#5        UR                  S5        Mk     U(       a  U R4                  (       a  [7        Xx5      u  n$n%/ n&[        R8                  " X5       H}  u  n'n([;        U'U&U$U%U(5      (       d  M  UR                  S5        U(       a  UU'/-   OUU'/n)U(       a  Un*OUn*[=        U'U$U%5      u  n+n,[?        U(UUU*U)SUU+U,SS 9
n-UR                  U-5        M     SR                  U5      $ )!ax  Generate reStructuredText documentation for a CLI application.

Parameters
----------
app : App
    The cyclopts App instance to document.
recursive : bool
    If True, generate documentation for all subcommands recursively.
    Default is True.
include_hidden : bool
    If True, include hidden commands/parameters in documentation.
    Default is False.
heading_level : int
    Starting heading level for the main application title.
    Default is 1 (uses '=' markers).
command_chain : list[str]
    Internal parameter to track command hierarchy.
    Default is None.
generate_toc : bool
    If True, generate a table of contents for multi-command apps.
    Default is True.
flatten_commands : bool
    If True, generate all commands at the same heading level instead of nested.
    Default is False.
commands_filter : list[str], optional
    If specified, only include commands in this list.
    Supports nested command paths like "db.migrate".
    Default is None (include all commands).
exclude_commands : list[str], optional
    If specified, exclude commands in this list.
    Supports nested command paths like "db.migrate".
    Default is None (no exclusions).
no_root_title : bool
    If True, skip generating the root application title.
    Useful when embedding in existing documentation with its own title.
    Default is False.

Returns
-------
str
    The generated RST documentation.
r   )RstFormatterNr   r4   cycloptsr   /z.. _:rA   help_formatrestructuredtext)fallback)rP   rst)preserve_markupz
**Usage:**F)r2   zUsage:zUsage: z::
z    )rD   r1   	argumentsoptionsgroupedz**Arguments:**z**Options:**)	rC   r1   rD   rE   rF   rG   r   r	   rH   ) cyclopts.help.formatters.rstrJ   r   get_app_infor   r   r8   r)   r   r6   r   	app_stackresolveextract_descriptionr   stripextract_usage
isinstancestrformat_usage_linesplit_assemble_help_panelscategorize_panelsresettitle
get_outputr   r   r5   r&   r/   generate_rst_docs).r0   rC   r1   rD   rE   rF   rG   r   r	   rH   rJ   r>   r?   full_command
base_titlerf   anchor_partsanchor_nameeffective_heading_levelheader_linesrO   descriptionpreserve	desc_textusage
usage_textlinehelp_panels_with_groups	formattercategorizedargument_panelsoption_panelsgrouped_panelsr   paneloutputr   r   r   r   r   subcommand_chainnext_heading_levelr*   r,   subdocss.                                                 r   rh   rh      s]   l :E)9)F)Fs)Z&HJ/2=/AA/Eqr*+=Y[K\ <LM*H%((<(00c:BB3LRRTK	LL4}A&'	LL ]"/	m"/ MZ-#m2D"Dq"H_l-.u6MN\"R--''@R'SK"66sKHK "== dHM	LL*+LL -]\"R - ..s3
%%%"
)%uM
 -??
Mbde
 :%'//"=CCE
 #:,/JLLLL"((.tD6]+ /LL "77KH =1+<^\I #445Ln]K!+.O	*M +N m%&R'HAuOOEKdD%())+113FvV$R  ( 	-^$R &HAuOOEKdD%())+113FvV$R  & 'HAuOOdD%())+113FvV$R  ' S]]B\C
?"$?  -==cRLD&*k#=?Z\b   LL :G}v5XW[L\%2" &3" 9W02M95!5 (#-0."!1 3!5#G LL!I SL 99Ur'   )NN)FrA   NNN)N)	TFr   NTFNNF)__doc__typingr   cyclopts._markupr   cyclopts.docs.baser    cyclopts.help.formatters._sharedr   cyclopts.corer   listr`   tuplesetr   boolr&   r/   r7   rB   intrh    r'   r   <module>r      s   ?   ) / D! )-)-2#Y%23i$&2 3s8d?CHtO+,2:8
8c8 !$C48 "%SD	8
 8 
8v/5
/5 #C4/5 "%SD/5 49tT#Y--.	/5h !(,)-$(0	00 0 #Y%	0
 3i$&0 cT!0 
%S%
 !0h VZ
9
 $U3U?%; <
HKd

	
  &*"(,)-v	vv v 	v
 9t#v v v #Y%v 3i$&v v 	vr'   