
    kj(                        d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
mZmZ d dlZd dlmZmZ d dlmZmZ  ede
ej                           Zeeej                 eeej        f         f         Z G d d	          Z G d
 d          ZdS )    )OrderedDict)
AnyDictIterableListOptionalSequenceTupleTypeTypeVarUnionN)
first_boolpick_not_none)HelpSectionensure_is_cloup_formatterCommandType)boundc                       e Zd ZdZ	 	 ddededefdZeddededd fd	            Z	dde
j        dee         dd
fdZdeeee
j        f                  fdZdefdZdefdZd
S )Sectiona  
    A group of (sub)commands to show in the same help section of a
    ``MultiCommand``. You can use sections with any `Command` that inherits
    from :class:`SectionMixin`.

    .. versionchanged:: 0.6.0
        removed the deprecated old name ``GroupSection``.

    .. versionchanged:: 0.5.0
        introduced the new name ``Section`` and deprecated the old ``GroupSection``.
     Ftitlecommands	is_sortedc                    t          |t                    st          d          || _        || _        t                      | _        t          |t                    r/t                      | _        |D ]}|                     |           dS t          |t                    rt          |          | _        dS t          d          )z
        :param title:
        :param commands: sequence of commands or dict of commands keyed by name
        :param is_sorted:
            if True, ``list_commands()`` returns the commands in lexicographic order
        zFthe first argument must be a string, the title; you probably forgot itzVargument `commands` must be a sequence of commands or a dict of commands keyed by nameN)

isinstancestr	TypeErrorr   r   r   r   r	   add_commanddict)selfr   r   r   cmds        J/home/agentuser/manim-venv/lib/python3.11/site-packages/cloup/_sections.py__init__zSection.__init__   s     %%% 	ZXZ Z Z
"9Dh)) 	C'MMDM & &  %%%%& &$'' 	C'11DMMM B C C C    returnc                      | ||d          S )NT)r   r   )clsr   r   s      r"   sortedzSection.sorted5   s    s5(d3333r$   Nr!   namec                     |p|j         }|st          d          || j        v rt          d| d          || j        |<   d S )Nzmissing command namez	command "z" already exists)r)   r   r   	Exception)r    r!   r)   s      r"   r   zSection.add_command9   s^    sx 	423334=  >>>>???!dr$   c                     d | j                                         D             }| j        r|                                 |S )Nc                 *    g | ]\  }}|j         ||fS r   )hidden).0r)   r!   s      r"   
<listcomp>z)Section.list_commands.<locals>.<listcomp>B   s6     + + +	c"z+s + + +r$   )r   itemsr   sort)r    command_lists     r"   list_commandszSection.list_commandsA   sO    + +T]5H5H5J5J + + +> 	 r$   c                 *    t          | j                  S N)lenr   r    s    r"   __len__zSection.__len__H   s    4=!!!r$   c                 B    d                     | j        | j                  S )NzSection({}, is_sorted={}))formatr   r   r8   s    r"   __repr__zSection.__repr__K   s    *11$*dnMMMr$   )r   F)r   r6   )__name__
__module____qualname____doc__r   Subcommandsboolr#   classmethodr(   clickCommandr   r   r   r
   r4   intr9   r<   r   r$   r"   r   r      s5       
 
 *,#(C Cc C&C C C C C2 4 43 4+ 4y 4 4 4 [4" "u} "HSM "T " " " "tE#u}*<$=>    " " " " "N# N N N N N Nr$   r   c                       e Zd ZdZdddddedeeeej	        f                  de
e         dee         d	ef
 fd
Z	 	 d dej	        dee         dee         ddfdZdeddfdZdedej	        dedefdZ	 	 	 d!dej	        dee         dee         deddf
 fdZ	 d"dej        dedee         fdZdej        dedej	        defdZdej        dedee         fdZ	 d"deej                 dedefdZdej        dej        ddfdZ xZS )#SectionMixina  
    Adds to a :class:`click.MultiCommand` the possibility of organizing its subcommands
    into multiple help sections.

    Sections can be specified in the following ways:

    #. passing a list of :class:`Section` objects to the constructor setting
       the argument ``sections``
    #. using :meth:`add_section` to add a single section
    #. using :meth:`add_command` with the argument `section` set

    Commands not assigned to any user-defined section are added to the
    "default section", whose title is "Commands" or "Other commands" depending
    on whether it is the only section or not. The default section is the last
    shown section in the help and its commands are listed in lexicographic order.

    .. versionchanged:: 0.8.0
        this mixin now relies on ``cloup.HelpFormatter`` to align help sections.
        If a ``click.HelpFormatter`` is used with a ``TypeError`` is raised.

    .. versionchanged:: 0.8.0
        removed ``format_section``. Added ``make_commands_help_section``.

    .. versionadded:: 0.5.0
    Nr   )r   sectionsalign_sectionsargsr   rI   rJ   kwargsc                     t                      j        |d|i| || _        t          d|pg           | _        g | _        | j        h| _        |D ]}|                     |           dS )a.  
        :param align_sections:
            whether to align the columns of all subcommands' help sections.
            This is also available as a context setting having a lower priority
            than this attribute. Given that this setting should be consistent
            across all you commands, you should probably use the context
            setting only.
        :param args:
            positional arguments forwarded to the next class in the MRO
        :param kwargs:
            keyword arguments forwarded to the next class in the MRO
        r   	__DEFAULT)r   N)superr#   rJ   r   _default_section_user_sections_section_setadd_section)r    r   rI   rJ   rK   rL   section	__class__s          r"   r#   zSectionMixin.__init__j   s    & 	$<<V<<<, 'hn" M M M-/!23 	& 	&GW%%%%	& 	&r$   r!   r)   rT   r%   c                     |p|j         }|| j        }|                    ||           || j        vr6| j                            |           | j                            |           dS dS )zFAdd a command to the section (if specified) or to the default section.N)r)   rP   r   rR   rQ   appendadd)r    r!   r)   rT   s       r"   _add_command_to_sectionz$SectionMixin._add_command_to_section   s}     sx?+GC&&&$+++&&w///!!'***** ,+r$   c                    || j         v rt          d| d          | j                            |           | j                             |           |j                                        D ]\  }}|                     ||d           dS )zAdd a :class:`Section` to this group. You can add the same
        section object only a single time.

        See Also:
            :meth:`section`
        z	section "z" was already addedF)fallback_to_default_sectionN)rR   
ValueErrorrQ   rW   rX   r   r1   r   )r    rT   r)   r!   s       r"   rS   zSectionMixin.add_section   s     d'''EEEEFFF""7+++g&&& )//11 	K 	KID# S$EJJJJ	K 	Kr$   r   attrsc                 L    t          ||fi |}|                     |           |S )zDCreate a new :class:`Section`, adds it to this group and returns it.)r   rS   )r    r   r   r]   rT   s        r"   rT   zSectionMixin.section   s2    %33U33!!!r$   Tr[   c                     t                                          ||           |s|r|                     |||           dS dS )a  
        Add a subcommand to this ``Group``.

        **Implementation note:** ``fallback_to_default_section`` looks not very
        clean but, even if it's not immediate to see (it wasn't for me), I chose
        it over apparently cleaner options.

        :param cmd:
        :param name:
        :param section:
            a ``Section`` instance. The command must not be in the section already.
        :param fallback_to_default_section:
            if ``section`` is None and this option is enabled, the command is added
            to the "default section". If disabled, the command is not added to
            any section unless ``section`` is provided. This is useful for
            internal code and subclasses. Don't disable it unless you know what
            you are doing.
        N)rO   r   rY   )r    r!   r)   rT   r[   rU   s        r"   r   zSectionMixin.add_command   sW    0 	C&&& 	=1 	=((dG<<<<<	= 	=r$   ctxinclude_default_sectionc                    t          | j                  }|rmt          | j                  dk    rUt                              t          | j                  dk    rdnd| j        j                  }|                    |           |S )z
        Return the list of all sections in the "correct order".

        If ``include_default_section=True`` and the default section is non-empty,
        it will be included at the end of the list.
        r   zOther commandsCommands)r   r   )listrQ   r7   rP   r   r(   r   rW   )r    r`   ra   section_listdefault_sections        r"   list_sectionszSectionMixin.list_sections   s     D/00" 	1s4+@'A'AA'E'E%nn*-d.A*B*BQ*F*F&&J.7 - 9 9O 000r$   c                     |S )a  Used to format the name of the subcommands. This method is useful
        when you combine this extension with other click extensions that override
        :meth:`format_commands`. Most of these, like click-default-group, just
        add something to the name of the subcommands, which is exactly what this
        method allows you to do without overriding bigger methods.
        r   )r    r`   r)   r!   s       r"   format_subcommand_namez#SectionMixin.format_subcommand_name   s	     r$   c                 |     |                                 }|sd S t          |j         fd|D                       S )Nc                 R    g | ]#\  }}                     ||          |j        f$S r   )ri   get_short_help_str)r/   r)   r!   r`   r    s      r"   r0   z;SectionMixin.make_commands_help_section.<locals>.<listcomp>   sG       D# ,,S$<<c>TU  r$   )headingdefinitions)r4   r   r   )r    r`   rT   visible_subcommandss   ``  r"   make_commands_help_sectionz'SectionMixin.make_commands_help_section   sl     &3355" 	4M    !4  
 
 
 	
r$   defaultc                 L    t          | j        t          |dd           |          S )NrJ   )r   rJ   getattr)r    r`   rq   s      r"   must_align_sectionsz SectionMixin.must_align_sections   s/     C)400
 
 	
r$   	formatterc                      t          |          }                               }t           fd|D                       }|sd S |                    |                                          d S )Nc              3   D   K   | ]}                     |          V  d S r6   )rp   )r/   rT   r`   r    s     r"   	<genexpr>z/SectionMixin.format_commands.<locals>.<genexpr>   sG       &
 &
 ++C99&
 &
 &
 &
 &
 &
r$   )aligned)r   rg   r   write_many_sectionsrt   )r    r`   ru   subcommand_sectionshelp_sectionss   ``   r"   format_commandszSectionMixin.format_commands   s    -i88	"0055% &
 &
 &
 &
 &
.&
 &
 &
 
 
  	F%%4#;#;C#@#@ 	& 	
 	
 	
 	
 	
r$   )NN)NNT)T)r=   r>   r?   r@   r   r   r   r   rD   rE   r   r   rB   r#   rY   rS   rT   r   Contextr   rg   ri   r   rp   rt   HelpFormatterr}   __classcell__)rU   s   @r"   rH   rH   O   s        8 8<&()-	& & &&4U] 234& 7#& !	&
 & & & & & &: #%)+ +=+sm+ '"+ 
	+ + + +K7 Kt K K K K S U] S W     #%),0	= ===sm= '"= &*	=
 
= = = = = =: CG =;?	g   "	=	(+	27-			 	 	 	
=
+2
	+	
 
 
 
 =A
 
EM*
59
	
 
 
 

5= 
U=P 
UY 
 
 
 
 
 
 
 
r$   rH   )collectionsr   typingr   r   r   r   r   r	   r
   r   r   r   rD   cloup._utilr   r   cloup.formattingr   r   rE   r   r   rA   r   rH   r   r$   r"   <module>r      st   # # # # # #                         1 1 1 1 1 1 1 1 C C C C C C C Cgm4+>???HU]+T#u}2D-EEF=N =N =N =N =N =N =N =N@v
 v
 v
 v
 v
 v
 v
 v
 v
 v
r$   