
    !<iA                        d Z ddlmZ ddlmZ ddlmZ ddlmZ erddl	m
Z
 	 	 d'dee         dz  d	ee         dz  d
eee         dz  ee         dz  f         fdZdedee         dee         dz  dee         dz  ddd
efdZdedee         dz  dee         dz  d
eee         dz  ee         dz  f         fdZ	 	 	 	 	 d(dddededee         dz  d	ee         dz  dee         dz  d
eeeedf                  fdZ	 d)dee         deeeedf                  dedz  d
dfdZ	 	 	 	 	 	 	 	 	 d*ddd eded!ed"ee         dz  d#ed$edee         dz  d	ee         dz  d%ed
efd&ZdS )+z9RST documentation generation functions for cyclopts apps.    )TYPE_CHECKING)extract_text)BaseDocGenerator)make_rst_section_header)AppNcommands_filterexclude_commandsreturnc                 J    d}| d | D             }d}|rd |D             }||fS )a  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.
    Nc                 :    h | ]}|                     d d          S _-replace.0cmds     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/cyclopts/docs/rst.py	<setcomp>z-_normalize_command_filters.<locals>.<setcomp>!   s&    OOOckk#s33OOO    c                 :    h | ]}|                     d d          S r   r   r   s     r   r   z-_normalize_command_filters.<locals>.<setcomp>%   s&    PPPckk#s33PPPr    )r   r	   normalized_includenormalized_excludes       r   _normalize_command_filtersr      sT    $ "OOOOO QPP?OPPP111r   nameparent_pathnormalized_commands_filternormalized_exclude_commandssubappr   c                 
   |rd                     || gz             n| }|rP| |v s||v rdS t          t          |                    D ])}d                     |d|dz                      }||v r dS *|| |v s||v rdS t          t          |                    D ])}d                     |d|dz                      }||v r dS *|s| |v rdS t          |d          r'|j        r |D ]}|                    |dz             r dS dS dS )a9  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>Gv-...4I" ...)?Z2Z2Z5s;''(( 	 	A XXk'AE'&:;;N!<<<uu = "---->X1X1X4s;''(( 	 	A XXk'AE'&:;;N!;;;tt <  	t'AAA46;'' 	 F,< 	 8    
((S99  44  u4r   c                    d}|ug }|D ]h}|                     | dz             rD|t          |           dz   d         }|                    |                    dd                     ^|| k    rd} ni|g k    rg }d}|rg }|D ]}|                     | dz             rD|t          |           dz   d         }|                    |                    dd                     ^|                    |                    dd                     ||fS )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_subcommandr7   e   s_   * !- 4 	 	J$$TCZ00 'D		A8
#**:+=+=c3+G+GHHHHt##&*# $
 "$$"$" K!6 	K 	KK%%dSj11 K)#d))a-//:$++K,?,?S,I,IJJJJ$++K,?,?S,I,IJJJJ 444r   F appinclude_hiddenprefixc           	         g }| j         s|S |g }t          ||          \  }}t          j        | |          D ]\  }	}
t	          |	||||
          s|r| |	 n|	}|                    dd                                          }|                    |||
f           ||	gz   }t          |
|| d|||          }|	                    |           |S )zwRecursively collect all commands for table of contents.

    Returns a list of (display_name, anchor, app) tuples.
    N r   )r:   r;   r   r	   r   )
r%   r   r   iterate_commandsr/   r   lowerr1   _collect_commands_for_tocextend)r9   r:   r;   r   r	   r   commandsr   r    r   r!   display_nameanchornested_pathnesteds                  r   r@   r@      s1    H= >X)? ?; ;
 )9#~NN    f&+9;VX^
 
 	 ,2<&($(((%%c3//5577vv6777!TF**)"%%%+-#
 
 
 	Or   linesrB   app_namec                     |sdS |                      d           |                      d           |                      d           |                      d           dS )z5Generate TOC entries with proper indentation for RST.Nz.. contents:: Commandsz
   :local:z   :depth: 2r8   )r1   )rG   rB   rH   s      r   _generate_toc_entriesrJ      s`      	LL)***	LL	LL   	LLr   Tr$   	recursiveheading_levelcommand_chaingenerate_tocflatten_commandsno_root_titlec
                 ^   ddl m}
 g }|g }t          j        | |          \  }}}|r9t	          |          dk    rd                    |dd                   n|d         }n|}dg}|r|                    |           n|                    |           d                    |                              dd                              d	d          	                                }|                    d
| d           |                    d           |	r|s|}n |r|r|}n|r|t	          |          z   dz
  n|}|	r|r:t          ||          }|                    |           |                    d           | j                            dd          }t          j        | |          }|rT|dv }t          |d|          }|r<|                    |                                           |                    d           |	r|r,|r*|                    d           |                    d           |	r|rt          j        |           }d}|rtt#          |t$                    r|}nt          |dd          }|rt          j        ||d          }d|v r(|                    dd                                          }d| }|ro|                    d           |                    d           |                    d          D ]}|                    d|            |                    d           |                     g |          } |
|dz   |          }t          j        ||          }|d         }|d         }|d         } |r|	r|r|                    d           |                    d           |D ]\  }!}"|                                 d|"_         |dd|"           |                                                                }#|#r*|                    |#           |                    d           |s| r,|	r|r'|                    d           |                    d           |D ]\  }!}"|                                 d|"_         |dd|"           |                                                                }#|#r*|                    |#           |                    d           | D ]x\  }!}"|                                  |dd|"           |                                                                }#|#r*|                    |#           |                    d           y|r| j        rt7          ||          \  }$}%g }&t          j        | |          D ]\  }'}(t;          |'|&|$|%|(          s|                    d           |r||'gz   n||'g})|r|}*n|}*t=          |'|$|%          \  }+},t?          |(|||*|)d||+|,d 
  
        }-|                    |-           d                    |          S )!a  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$   r=   cycloptsr   /z.. _:r8   help_formatrestructuredtext)fallback)rX   rst)preserve_markupz
**Usage:**F)r;   zUsage:zUsage: z::
z    )rL   r:   	argumentsoptionsgroupedz**Arguments:**z**Options:**)	rK   r:   rL   rM   rN   rO   r   r	   rP   ) cyclopts.help.formatters.rstrR   r   get_app_infor(   r&   rA   r1   r   r?   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   r>   r/   r7   generate_rst_docs).r9   rK   r:   rL   rM   rN   rO   r   r	   rP   rR   rG   rH   full_command
base_titlern   anchor_partsanchor_nameeffective_heading_levelheader_linesrW   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_levelr2   r4   subdocss.                                                 r   rp   rp      s   l :99999E)9)FsM)Z)Z&HlJ /2=/A/AA/E/Eqrr*+++=Y[K\ <L &M****H%%%((<((00c::BB3LLRRTTK	LL&&&&'''	LL  m] m"/	 mm m"/ MZ"l-#m2D2D"Dq"H"H_l - .u6MNN\"""R-''@R'SSK"6sKHHK  "== dHMMM	 	LL**+++LL  - ] \"""R  -  .s33
 	0%%% N"

)%uMMM
  f-?
Mbdeee
 :%%'//"==CCEE
 0://J 	LLLL"((.. , ,]D]]++++LL "77KHH =1+<^\\\I #45Ln]]K!+.O	*M +N  ! !m !%&&&R' 	! 	!HAuOOEKIdD%((())++1133F !V$$$R    	 ! !- ! !^$$$R & 	! 	!HAuOOEKIdD%((())++1133F !V$$$R    ' 	! 	!HAuOOIdD%((())++1133F !V$$$R     -"S] -"B\-C
 C
?"$?  -=c>RR $	" $	"LD&*k#=?Z\b    LL :G\}v55XW[L\ 3%2"" &3" 9W02M9 95!5 (#-0."!1 3!5#  G LL!!!!99Ur   )NN)Fr8   NNN)N)	TFr$   NTFNNF)__doc__typingr   cyclopts._markupr   cyclopts.docs.baser    cyclopts.help.formatters._sharedr   cyclopts.corer   listrh   tuplesetr   boolr/   r7   r@   rJ   intrp   r   r   r   <module>r      sa   ? ?             ) ) ) ) ) ) / / / / / / D D D D D D "!!!!!! )-)-2 2#Y%23i$&2 3s8d?CHtO+,2 2 2 2:8
8c8 !$C48 "%SD	8
 8 
8 8 8 8v/5
/5 #C4/5 "%SD/5 49tT#Y--.	/5 /5 /5 /5h !(,)-$(0 0	00 0 #Y%	0
 3i$&0 cT!0 
%S%
 !0 0 0 0h VZ
 
9
 $U3U?%; <
HKd

	
 
 
 
  &*"(,)-v v	vv v 	v
 9t#v v v #Y%v 3i$&v v 	v v v v v vr   