U
    d                     @   sV   d Z ddlZddlZddlZG dd dZG dd deejZG dd deejZdS )	zT
Extension for ``click`` to provide a group
with a git-like *did-you-mean* feature.
    Nc                       sl   e Zd ZdZejejdd fddZejej	e
 ejeje
 ejej ej	e
 f d fddZ  ZS )	DYMMixinz
    Mixin class for click MultiCommand inherited classes
    to provide git-like *did-you-mean* functionality when
    a certain command is not registered.
    N)argskwargsreturnc                    s.   | dd| _| dd| _t j|| d S )Nmax_suggestions   cutoffg      ?)popr   r   super__init__)selfr   r   	__class__ =/tmp/pip-unpacked-wheel-36rv8y4n/click_didyoumean/__init__.pyr      s    zDYMMixin.__init__)ctxr   r   c              
      s   zt t| ||W S  tjjk
r } zjt|}tj|d }t	
|| || j| j}|rd|}|d7 }|d| 7 }tj||jW 5 d}~X Y nX dS )z
        Overrides clicks ``resolve_command`` method
        and appends *Did you mean ...* suggestions
        to the raised exception message.
        r   z
    z

zDid you mean one of these?
    N)r
   r   resolve_commandclick
exceptionsZ
UsageErrorstrutilsZmake_strdifflibget_close_matchesZlist_commandsr   r   joinr   )r   r   r   error	error_msgZoriginal_cmd_namematchesZfmt_matchesr   r   r   r      s     

zDYMMixin.resolve_command)__name__
__module____qualname____doc__typingAnyr   r   ContextListr   TupleOptionalCommandr   __classcell__r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdS )DYMGroupz
    click Group to provide git-like
    *did-you-mean* functionality when a certain
    command is not found in the group.
    Nr   r   r   r    r   r   r   r   r)   5   s   r)   c                   @   s   e Zd ZdZdS )DYMCommandCollectionz
    click CommandCollection to provide git-like
    *did-you-mean* functionality when a certain
    command is not found in the group.
    Nr*   r   r   r   r   r+   =   s   r+   )	r    r   r!   r   r   Groupr)   ZCommandCollectionr+   r   r   r   r   <module>   s   )