
    Vh                     ~    d dl mZmZmZ eZdZdZd dlZd dl	m
Z
 d Zd ZddZd	 Zd
 Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: homebrew_tap
author:
  - "Indrajit Raychaudhuri (@indrajitr)"
  - "Daniel Jaouen (@danieljaouen)"
short_description: Tap a Homebrew repository
description:
  - Tap external Homebrew repositories.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - The GitHub user/organization repository to tap.
    required: true
    aliases: ['tap']
    type: list
    elements: str
  url:
    description:
      - The optional git URL of the repository to tap. The URL is not assumed to be on GitHub, and the protocol does not have
        to be HTTP. Any location and protocol that git can handle is fine.
      - O(name) option may not be a list of multiple taps (but a single tap instead) when this option is provided.
    required: false
    type: str
  state:
    description:
      - State of the repository.
    choices: ['present', 'absent']
    required: false
    default: 'present'
    type: str
  path:
    description:
      - A V(:) separated list of paths to search for C(brew) executable.
    default: '/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin'
    type: path
    version_added: '2.1.0'
requirements: [homebrew]
a%  
- name: Tap a Homebrew repository, state present
  community.general.homebrew_tap:
    name: homebrew/dupes

- name: Tap a Homebrew repository, state absent
  community.general.homebrew_tap:
    name: homebrew/dupes
    state: absent

- name: Tap a Homebrew repository, state present
  community.general.homebrew_tap:
    name: homebrew/dupes,homebrew/science
    state: present

- name: Tap a Homebrew repository using url, state present
  community.general.homebrew_tap:
    name: telemachus/brew
    url: 'https://bitbucket.org/telemachus/brew'
N)AnsibleModulec                 N    t        j                  d      }|j                  |       S )z!Returns True if the tap is valid.z^([\w-]+)/(homebrew-)?([\w-]+)$)recompilematch)tapregexs     r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/homebrew_tap.pya_valid_tapr   X   s     JJ9:E;;s    c                    | j                  |dg      \  }}}|j                  d      D cg c]#  }|s|j                         j                         % }}t	        j
                  dd|j                               }||v S c c}w )zReturns True if already tapped.r   
z	homebrew- )run_commandsplitstriplowerr   sub)	module	brew_pathr   rcouterrtap_tapstap_names	            r   already_tappedr    ^   s|     %%' LBS
 .1YYt_ETDJJL EDEvvk2syy{3Ht Fs
   A> A>c                     d\  }}}t        |      sd}d|z  }nat        | ||      sO| j                  r| j                  d       | j	                  |d||g      \  }}}	|dk(  rd}d|z  }nd}d|d	|	}nd
|z  }|||fS )zAdds a single tap.FFr   Tnot a valid tap: %schangedr   r   zsuccessfully tapped: %szfailed to tap:  due to zalready tapped: %sr   r    
check_mode	exit_jsonr   )
r   r   r   urlfailedr%   msgr   r   r   s
             r   add_tapr-   l   s    +FGSs#c)FIs3T*))	+
 C 7G+c1CF36<C #S(GS!!r   c                     d\  }}}}}|D ]$  }t        | ||      \  }}}|r n|r|dz  } |dz  }& |rd|z   }|||fz  }n|r
d}d||fz  }nd||fz  }|||fS )zAdds one or more taps.FFr   r   r      z!added: %d, unchanged: %d, error: Tzadded: %d, unchanged: %d)r-   )	r   r   r   r+   r%   	unchangedaddedr,   r   s	            r   add_tapsr3      s    -C*FGYs !(C!@#QJENI 1C7UI&&	(E9+==(E9+==GS!!r   c                    d\  }}}t        |      sd}d|z  }nht        | ||      rV| j                  r| j                  d       | j	                  |d|g      \  }}}t        | ||      sd}d|z  }nd}d|d|}nd	|z  }|||fS )
zRemoves a single tap.r"   Tr#   r$   untapzsuccessfully untapped: %szfailed to untap: r&   zalready untapped: %sr'   )	r   r   r   r+   r%   r,   r   r   r   s	            r   
remove_tapr6      s    +FGSs#c)		3	/T*))+
 C
 fi5G-3CF58#>C %s*GS!!r   c                     d\  }}}}}|D ]$  }t        | ||      \  }}}|r n|r|dz  } |dz  }& |rd|z   }|||fz  }n|r
d}d||fz  }nd||fz  }|||fS )zRemoves one or more taps.r/   r0   z#removed: %d, unchanged: %d, error: Tzremoved: %d, unchanged: %d)r6   )	r   r   r   r+   r%   r1   removedr,   r   s	            r   remove_tapsr9      s    /E,FGY !+FIs!C#qLGNI 3c9Wi((	*gy-AA*gy-AAGS!!r   c                     t        t        t        dgddd      t        d d      t        ddd	g
      t        ddd            d      } | j                  d   }|r|j                  d      }| j	                  dd|      }| j                  d   }| j                  d   }| j                  d   dk(  ru|t        | ||      \  }}}n8t        |      dkD  rd}| j                  |       nt        | ||d   |      \  }}}r| j                  |       y | j                  |       y | j                  d   d	k(  r:t        | ||      \  }}}|r| j                  |       y | j                  ||       y y )Nr   listTstr)aliasestyperequiredelementsF)defaultr?   presentabsent)rA   choicesz?/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/binpath)rA   r?   r>   )namer*   staterE   )argument_specsupports_check_mode:brew)r?   opt_dirsrF   r*   rG   r0   z<List of multiple taps may not be provided with 'url' option.)r,   r   )r%   r,   )r   dictparamsr   get_bin_pathr3   len	fail_jsonr-   r)   r9   )r   rE   r   r   r*   r+   r%   r,   s           r   mainrR      s   ugFTERTE2y9h2GHY		
 !F == Dzz### $ I == D
--
C}}W*; $,FIt#D FGS 4y1}T  S )'.vy$q'3'O$%W#6	w	8	+*69dC%W#6 
,r   __main__)N)
__future__r   r   r   r>   __metaclass__DOCUMENTATIONEXAMPLESr   ansible.module_utils.basicr   r   r    r-   r3   r6   r9   rR   __name__ r   r   <module>r[      sb    A @,\* 
 4">"2"<"257p zF r   