
    ljS                        d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	Z	ddl
mZ dgZerddlmZmZ  G d	 de	j                  ZdS )
a  ``DefaultGroup`` allows a subcommand to act as the main command.

In particular, this class is what allows ``manim`` to act as ``manim render``.

.. note::
    This is a vendored version of https://github.com/click-contrib/click-default-group/
    under the BSD 3-Clause "New" or "Revised" License.

    This library isn't used as a dependency, as we need to inherit from
    :class:`cloup.Group` instead of :class:`click.Group`.
    )annotationsN)Callable)TYPE_CHECKINGAny)
deprecatedDefaultGroup)CommandContextc                  l     e Zd ZdZd fdZdd
Zd fdZd fdZd fdZe	d fd            Z
 xZS )r   a  Invokes a subcommand marked with ``default=True`` if any subcommand is not
    chosen.

    Parameters
    ----------
    *args
        Positional arguments to forward to :class:`cloup.Group`.
    **kwargs
        Keyword arguments to forward to :class:`cloup.Group`. The keyword
        ``ignore_unknown_options`` must be set to ``False``.

    Attributes
    ----------
    default_cmd_name : str | None
        The name of the default command, if specified through the ``default``
        keyword argument. Otherwise, this is set to ``None``.
    default_if_no_args : bool
        Whether to include or not the default command, if no command arguments
        are supplied. This can be specified through the ``default_if_no_args``
        keyword argument. Default is ``False``.
    argsr   kwargsc                    |                     dd          st          d          d| _        |                    dd           | _        |                    dd          | _         t                      j        |i | d S )Nignore_unknown_optionsTz%Default group accepts unknown optionsdefaultdefault_if_no_argsF)get
ValueErrorr   popdefault_cmd_namer   super__init__)selfr   r   	__class__s      R/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/cli/default_group.pyr   zDefaultGroup.__init__4   s    zz2D99 	FDEEE&*#,2JJy$,G,G(.

3G(O(O$)&)))))    commandr	   returnNonec                L    |j         }|                     |           || _        dS )zSets a command function as the default command.

        Parameters
        ----------
        command
            The command to set as default.
        N)nameadd_commandr   )r   r   cmd_names      r   set_default_commandz DefaultGroup.set_default_command=   s-     <!!! (r   ctxr
   	list[str]c                    |s)| j         r"| j        r|                    d| j                   t                                          ||          }|S )a}  Parses the list of ``args`` by forwarding it to
        :meth:`cloup.Group.parse_args`. Before doing so, if
        :attr:`default_if_no_args` is set to ``True`` and ``args`` is empty,
        this function appends to it the name of the default command specified
        by :attr:`default_cmd_name`.

        Parameters
        ----------
        ctx
            The Click context.
        args
            A list of arguments. If it's empty and :attr:`default_if_no_args`
            is ``True``, append the name of the default command to it.

        Returns
        -------
        list[str]
            The parsed arguments.
        r   )r   r   insertr   
parse_args)r   r$   r   parsed_argsr   s       r   r(   zDefaultGroup.parse_argsI   sW    (  	2/ 	2D4I 	2KK40111!&!3!3C!>!>r   r"   strCommand | Nonec                    || j         vr| j        r||j        d<   | j        }t                                          ||          S )a  Get a command function by its name, by forwarding the arguments to
        :meth:`cloup.Group.get_command`. If ``cmd_name`` does not match any of
        the command names in :attr:`commands`, attempt to get the default command
        instead.

        Parameters
        ----------
        ctx
            The Click context.
        cmd_name
            The name of the command to get.

        Returns
        -------
        :class:`click.Command` | None
            The command, if found. Otherwise, ``None``.
        arg0)commandsr   metar   get_command)r   r$   r"   r   s      r   r0   zDefaultGroup.get_commandb   sH    $ 4=((T-B('CHV,Hww""3111r   ,tuple[str | None, Command | None, list[str]]c                    t                                          ||          \  }}}d|j        v r*|                    d|j        d                    ||j        }|||fS )a  Given a list of ``args`` given by a CLI, find a command which
        matches the first element, and return its name (``cmd_name``), the
        command function itself (``cmd``) and the rest of the arguments which
        shall be passed to the function (``cmd_args``). If not found, return
        ``None``, ``None`` and the rest of the arguments.

        After resolving the command, if the Click context given by ``ctx``
        contains an ``arg0`` attribute in its :attr:`click.Context.meta`
        dictionary, insert it as the first element of the returned
        ``cmd_args``.

        Parameters
        ----------
        ctx
            The Click context.
        cmd_name
            The name of the command to get.

        Returns
        -------
        cmd_name : str | None
            The command name, if found. Otherwise, ``None``.
        cmd : :class:`click.Command` | None
            The command, if found. Otherwise, ``None``.
        cmd_args : list[str]
            The rest of the arguments to be passed to ``cmd``.
        r-   r   )r   resolve_commandr/   r'   r    )r   r$   r   r"   cmdr   s        r   r3   zDefaultGroup.resolve_commandz   sf    < $gg55c4@@#tSXKK38F+,,,8d""r   *Callable[[Callable[..., object]], Command]c                     |                     dd          } t                      j        |i ||sS t          j        dt
          d           d fd
}|S )a  Return a decorator which converts any function into the default
        subcommand for this :class:`DefaultGroup`.

        .. warning::
            This method is deprecated. Use the ``default`` parameter of
            :class:`DefaultGroup` or :meth:`set_default_command` instead.

        Parameters
        ----------
        *args
            Positional arguments to pass to :meth:`cloup.Group.command`.
        **kwargs
            Keyword arguments to pass to :meth:`cloup.Group.command`.

        Returns
        -------
        Callable[[Callable[..., object]], click.Command]
            A decorator which transforms its input into this
            :class:`DefaultGroup`'s default subcommand.
        r   FzBUse default param of DefaultGroup or set_default_command() instead   )
stacklevelfr   r   r	   c                H     |           }                     |           |S )N)r#   )r9   r4   	decoratorr   s     r   
_decoratorz(DefaultGroup.command.<locals>._decorator   s)    )A,,C$$S)))Jr   )r9   r   r   r	   )r   r   r   warningswarnDeprecationWarning)r   r   r   r   r<   r;   r   s   `    @r   r   zDefaultGroup.command   s    0 **Y..@OA
A
 A
	  	P	
 	
 	
 	
	 	 	 	 	 	 	
 r   )r   r   r   r   )r   r	   r   r   )r$   r
   r   r%   r   r%   )r$   r
   r"   r*   r   r+   )r$   r
   r   r%   r   r1   )r   r   r   r   r   r5   )__name__
__module____qualname____doc__r   r#   r(   r0   r3   r   r   __classcell__)r   s   @r   r   r      s         ,* * * * * *
) 
) 
) 
)     22 2 2 2 2 20## ## ## ## ## ##J ( ( ( ( ( Z( ( ( ( (r   )rC   
__future__r   r=   collections.abcr   typingr   r   cloupmanim.utils.deprecationr   __all__clickr	   r
   Groupr    r   r   <module>rN      s   
 
 # " " " " "  $ $ $ $ $ $ % % % % % % % %  . . . . . .
 '&&&&&&&&k k k k k5; k k k k kr   