
    !<ia(                     |    d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 erddl
mZmZ ddlmZmZ  G d d	          ZdS )
z)reStructuredText documentation formatter.    N)TYPE_CHECKINGAnyOptional)extract_text)make_rst_section_header)ConsoleConsoleOptions)	HelpEntry	HelpPanelc                   $   e Zd ZdZ	 	 ddedefdZdd	Zdefd
Z	de
d         de
d         ddddfdZded         de
d         ddfdZded         de
d         ddfdZde
d         de
d         deddfdZde
d         de
d         deddfdZdS )RstFormattera  reStructuredText documentation formatter.

    Parameters
    ----------
    heading_level : int
        Starting heading level for panels (default: 2).
    include_hidden : bool
        Include hidden commands/parameters in documentation (default: False).
       Fheading_levelinclude_hiddenc                 R    || _         || _        t          j                    | _        d S N)r   r   ioStringIO_output)selfr   r   s      /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/cyclopts/help/formatters/rst.py__init__zRstFormatter.__init__   s%    
 +,{}}    returnNc                 6    t          j                    | _        dS )z!Reset the internal output buffer.N)r   r   r   r   s    r   resetzRstFormatter.reset#   s    {}}r   c                 4    | j                                         S )zGet the accumulated RST output.

        Returns
        -------
        str
            The RST documentation string.
        )r   getvaluer   s    r   
get_outputzRstFormatter.get_output'   s     |$$&&&r   consoler   optionsr	   panelr   c                    |j         sdS |j        rZt          |j        |          }d                    t	          || j                            }| j                            | d           |j        r4t          |j        |          }|r| j                            | d           |j	        dk    r| 
                    |j         |           n&|j	        dk    r|                     |j         |           | j                            d           dS )a]  Format and render a help panel as RST.

        Parameters
        ----------
        console : Optional[Console]
            Console for rendering (used for extracting plain text).
        options : Optional[ConsoleOptions]
            Console rendering options (unused for RST).
        panel : HelpPanel
            Help panel to render.
        N


command	parameter)entriestitler   joinr   r   r   writedescriptionformat_format_command_panel_format_parameter_panel)r   r!   r"   r#   
title_textheader	desc_texts          r   __call__zRstFormatter.__call__1   s   " } 	F ; 	0%ek7;;JYY6z4CUVVWWFL&///  	7$U%6@@I 7""i#5#5#5666 <9$$&&u}g>>>>\[((((@@@4     r   r)   r
   c                 L   |D ]}g }|j         r|                    |j                    |j        r|                    |j                   |r|d         }| j                            d| d           t          |j        d          o1t          |j        j        d          od|j        j        j        j	        v }t          |j        ||          }|rPd                    d	 |                    d
          D                       }| j                            d| d           !dS )zFormat command entries as RST.

        Parameters
        ----------
        entries : list[HelpEntry]
            Command entries to format.
        console : Optional[Console]
            Console for text extraction.
        r   ````
primary_renderable	__class__RestructuredTextpreserve_markup c              3   f   K   | ],}|                                 |                                 V  -d S r   strip.0lines     r   	<genexpr>z5RstFormatter._format_command_panel.<locals>.<genexpr>|   s<      (c(c$VZV`V`VbVb(c(c(c(c(c(c(cr   r%       r&   N)namesextendshortsr   r,   hasattrr-   r8   r9   __name__r   r+   split)	r   r)   r!   entryrF   primary_namepreserve_rst_markupdescr3   s	            r   r/   z"RstFormatter._format_command_panelY   sQ     	? 	?EE{ *U[)))| +U\*** ?$Qx ""#:#:#:#:;;; E-/CDD f 1 DkRRf*e.?.R.\.ee $
 $E$5wPcddd ? !$(c(c$**TBRBR(c(c(c c cIL&&'=i'='='=>>>5	? 	?r   c                 2   |D ]}g }|j         r|                    |j                    |j        r|                    |j                   |r|j        o"|j        du ot          d |D                        }|rCd |D             }|r|d                                         n|d                                         }nd                    |          }| j        	                    d| d           g }t          |j        d          o1t          |j        j        d	          od
|j        j        j        j        v }	t          |j        ||	          }
|
r|                    |
           g }|r|j        r|                    d           n|j        r|s|                    d           |j        r<d                    d |j        D                       }|                    d|            |j        	t          |j        |d          }|j        rdt'          |j                  v rd}d}|D ]3}|                    d          r|}|                    d          r|s|}4|                                dk    r|r|                    d| d           ng|                                dk    r|r|                    d| d           n3|                    d| d           n|                    d| d           |j        r<d                    d |j        D                       }|                    d|            |rd                    d |d                             d          D                       }| j        	                    d|            |r1| j        	                    dd                    |           d           | j        	                    d           |r1| j        	                    dd                    |           d           dS )zFormat parameter entries as RST.

        Parameters
        ----------
        entries : list[HelpEntry]
            Parameter entries to format.
        console : Optional[Console]
            Console for text extraction.
        Nc              3   @   K   | ]}|                     d           V  dS )-N
startswithrB   ns     r   rD   z7RstFormatter._format_parameter_panel.<locals>.<genexpr>   s3      TvTvklUVUaUabeUfUfTvTvTvTvTvTvr   c                 <    g | ]}|                     d           |S )rR   rS   rU   s     r   
<listcomp>z8RstFormatter._format_parameter_panel.<locals>.<listcomp>   s)    'R'R'RaS@Q@Q'R'R'R'Rr   r   z, r6   r7   r8   r9   r:   r;   z**Required**c              3   "   K   | ]
}d | d V  dS r6   N )rB   cs     r   rD   z7RstFormatter._format_parameter_panel.<locals>.<genexpr>   s*      +N+N1JJJJ+N+N+N+N+N+Nr   z	Choices: Fboolz--no-z--truezDefault: ``falsec              3   "   K   | ]
}d | d V  dS rZ   r[   )rB   es     r   rD   z7RstFormatter._format_parameter_panel.<locals>.<genexpr>   s*      'J'Jq
Q


'J'J'J'J'J'Jr   zEnvironment variable: r=   c              3   f   K   | ],}|                                 |                                 V  -d S r   r?   rA   s     r   rD   z7RstFormatter._format_parameter_panel.<locals>.<genexpr>   s<      (l(l$_c_i_i_k_k(l(l(l(l(l(l(lr   r%   rE   z []r&   )rF   rG   rH   requireddefaultanyupperr+   r   r,   rI   r-   r8   r9   rJ   r   appendchoicestypestrrT   lowerenv_varrK   )r   r)   r!   rL   rF   is_positionalpositional_namesname_str
desc_partsrN   rO   metadatachoices_strdefault_strpositive_flagnegative_flagnameenv_strr3   s                      r   r0   z$RstFormatter._format_parameter_panel   s     W	I W	IEE{ *U[)))| +U\*** OI % v5=D3H vQTTvTvpuTvTvTvQvQvMv  0'R'R5'R'R'R$>Nd/288:::TYZ[T\TbTbTdTdHH  $yy//H ""#6#6#6#6777  

 E-/CDD f 1 DkRRf*e.?.R.\.ee $
 $E$5wPcddd ,%%d+++   4U^ 4OON3333^ 4M 4OON333= ?"&))+N+N+N+N+N"N"NKOO$=$=$=>>>=,".u}gW\"]"]"]Kz GfEJ&?&?(,(,$) 9 9D#w77 904!%!6!6 9'4 !948M&,,..&88]8$OO,K-,K,K,KLLLL(..00G;;;$OO,K-,K,K,KLLLL$OO,I+,I,I,IJJJJ (Ek(E(E(EFFF= H"ii'J'JEM'J'J'JJJGOO$FW$F$FGGG  
I !$(l(l*Q-BUBUVZB[B[(l(l(l l lIL&&'9i'9'9::: H**+F		(0C0C+F+F+FGGGL&&v.... IL&&'Gdii.A.A'G'G'GHHHoW	I W	Ir   usagec                 
   |r~t          ||          }|rn| j                            d           |                    d          D ] }| j                            d| d           !| j                            d           dS dS dS )a-  Render the usage line as RST.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        usage : Any
            The usage line content.
        z::

r%   rE   N)r   r   r,   rK   )r   r!   r"   ry   
usage_textrC   s         r   render_usagezRstFormatter.render_usage   s    "  	)%eW55J )""8,,,&,,T22 8 8DL&&d7777""4(((((	) 	)) )r   r-   c                 p    |r1t          ||          }|r!| j                            | d           dS dS dS )a5  Render the description as RST.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        description : Any
            The description content.
        r&   N)r   r   r,   )r   r!   r"   r-   r3   s        r   render_descriptionzRstFormatter.render_description   s\    "  	7$['::I 7""i#5#5#566666	7 	77 7r   )r   F)r   N)rJ   
__module____qualname____doc__intr]   r   r   rk   r    r   r4   listr/   r0   r   r|   r~   r[   r   r   r   r      s         $% %% % % % %% % % %'C ' ' ' '&!)$&! *+&! 	&!
 
&! &! &! &!P$?T+-> $?R[I\ $?ae $? $? $? $?LaItK/@ aI8T]K^ aIcg aI aI aI aIF))$) *+) 	)
 
) ) ) )67)$7 *+7 	7
 
7 7 7 7 7 7r   r   )r   r   typingr   r   r   cyclopts._markupr    cyclopts.help.formatters._sharedr   rich.consoler   r	   cyclopts.helpr
   r   r   r[   r   r   <module>r      s    / / 				 / / / / / / / / / / ) ) ) ) ) ) D D D D D D 34444444422222222B7 B7 B7 B7 B7 B7 B7 B7 B7 B7r   