
    Vh                      d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmc mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZ d d
lm Z m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dlm2Z2m3Z3 d dl4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z>m?Z?m@Z@  e<       ZAej                  dz   ZCg dZDi ZEg dZFddddd d!d"d#ZGd$d%d&d&d'ZHej                  ej                  ej                  ej                  ej                  ej                  d(ZOd) ZP G d* d+eQ      ZRd, ZSd- ZT G d. d/eeR      ZUd0 ZVd1 ZWd4d2ZXeYd3k(  r eX        yy)5    )annotations)CLIN)Path)	constants)context)option_helpers)list_collection_dirs)AnsibleErrorAnsibleOptionsErrorAnsibleParserErrorAnsiblePluginNotFound)	to_nativeto_text)is_sequence)	json_dump)	yaml_dump)string_types)read_docstub)	from_yaml)AnsibleDumper)list_plugins)action_loaderfragment_loader)AnsibleCollectionConfigAnsibleCollectionRef)_get_collection_name_from_path)stringc)Display)get_plugin_docsget_docstringget_versioned_doclink)rolekeyword)PlayRoleBlockTaskHandler)	inventorylookupmodulez[5mz[1mz[8mz[0mz[0;0mz[7mz[4m)BLINKBOLDHIDENORMALRESETREVERSE	UNDERLINEz*%s*z`%s`z[%s])r-   r2   MODULEPLUGIN)r3   REFLINKDEPCONSTANTr4   c                    	 t         j                  t        |              y # t        $ rC}t         j                  t	        j
                                t        dt        |      z        d }~ww xY w)NzXWe could not convert all the documentation into JSON as there was a conversion issue: %s)displayr   	TypeErrorvvv	traceback
format_excr
   r   )textes     ?/home/dcms/DCMS/lib/python3.12/site-packages/ansible/cli/doc.pyjdumprB   T   sl    F	$( FI((*+u  yB  CD  yE  E  F  	FFs   ! 	A->A((A-c                      e Zd ZdZej
                  D  cg c]  }d|z   	 c}} Zej
                  D  cg c]  }d|z   	 c}} ez   Zd Zd Z	d Z
ddZdd	Zd
 Zd ZddZddZyc c}} w c c}} w )	RoleMixinzA mixin containing all methods relevant to role argument specification functionality.

    Note: The methods for actual display of role data are not present here.
    mainargument_specsc                   |r#t         j                  j                  |d|d      }n t         j                  j                  |d      }|D ]E  }t         j                  j                  ||      }t         j                  j                  |      sC|} n i S 	 t	        |d      5 }	t        |	j                         |      }
|
i }
ddd       |
S # 1 sw Y   
S xY w# t        t        f$ r}t        d|d|d|	      d}~ww xY w)
a   Load and process the YAML for the first found of a set of role files

        :param str root: The root path to get the files from
        :param str files: List of candidate file names in order of precedence
        :param str role_name: The name of the role for which we want the argspec data.
        :param str collection: collection name or None in case of stand alone roles

        :returns: A dict that contains the data requested, empty if no data found
        rolesmetaNr)	file_namezCould not read the role 'z' (at )orig_exc)
ospathjoinexistsopenr   readIOErrorOSErrorr   )selfrootfiles	role_name
collection	meta_pathspecfile	full_pathrP   fdatar@   s               rA   _load_role_datazRoleMixin._load_role_datag   s     T7IvFIT62I  	HY9Iww~~i( 		 <I	mdC A T:<D   ! 	m$yZ^%_jkll	ms6   C ! CC CC C D 'C;;D c                H    | j                  || j                  ||      }|d= |S )a~  Load the roles metadata from the source file.

        :param str role_name: The name of the role for which we want the argspec data.
        :param str role_path: Path to the role/collection root.
        :param str collection: collection name or None in case of stand alone roles

        :returns: A dict of all role meta data, except ``argument_specs`` or an empty dict
        rF   )ra   ROLE_METADATA_FILES)rW   rZ   	role_pathr[   r`   s        rA   _load_metadatazRoleMixin._load_metadata   s/     ##It/G/GT^_!"    c                    	 | j                  || j                  ||      }|j                  di       }|S # t        $ r}d|dt	        |      |d}Y d}~|S d}~ww xY w)a  Load the role argument spec data from the source file.

        :param str role_name: The name of the role for which we want the argspec data.
        :param str role_path: Path to the role/collection root.
        :param str collection: collection name or None in case of stand alone roles

        We support two files containing the role arg spec data: either meta/main.yml
        or meta/argument_spec.yml. The argument_spec.yml file will take precedence
        over the meta/main.yml file, if it exists. Data is NOT combined between the
        two files.

        :returns: A dict of all data underneath the ``argument_specs`` top-level YAML
            key in the argspec data file. Empty dict is returned if there is no data.
        rF   zFailed to process role (): )error	exceptionN)ra   ROLE_ARGSPEC_FILESget	Exceptionr   )rW   rZ   rd   r[   r`   r@   s         rA   _load_argspeczRoleMixin._load_argspec   sk     	l''	43J3JIWabD88,b1D
   	lBKYWX\ZijkD	ls   04 	AAANc                   t               }t               }|D ]  }t        j                  j                  |      s#t        j                  |      D ]  }t        j                  j                  ||      }| j                  D ]s  }t        j                  j                  |d|      }	t        j                  j                  |	      sD|||v r)||vr%|j                  |       |j                  |d|f           |S )a  Find all non-collection roles that have an argument spec file.

        Note that argument specs do not actually need to exist within the spec file.

        :param role_paths: A tuple of one or more role paths. When a role with the same name
            is found in multiple paths, only the first-found role is returned.
        :param name_filters: A tuple of one or more role names used to filter the results.

        :returns: A set of tuples consisting of: role name, full role path
        rI   N)	setrO   rP   isdirlistdirrQ   rk   rR   add)
rW   
role_pathsname_filtersfoundfound_namesrP   entryrd   r]   r^   s
             rA   _find_all_normal_rolesz RoleMixin._find_all_normal_roles   s     e 	D77==& D) GGLLu5	 !% 7 7 H "Y IIww~~i0'/5L3H$K7 + 6 !&		5$	*B C		* rf   c           	        t               }t        |      }|D ]e  }t        |d      }t        |      }t        j
                  j                  |d      }t        j
                  j                  |      s\t	        j                  |      D ]  }	| j                  D ]  }
t        j
                  j                  ||	d|
      }t        j
                  j                  |      sE||j                  |	||f       n|D ]  }t        |j                  d            dk(  rG|j                  d      \  }}}dj                  ||g      |k(  sL|	|k(  sR|j                  |	||f       g||	k(  sm|j                  |	||f           h |S )a  Find all collection roles with an argument spec file.

        Note that argument specs do not actually need to exist within the spec file.

        :param name_filters: A tuple of one or more role names used to filter the results. These
            might be fully qualified with the collection name (e.g., community.general.roleA)
            or not (e.g., roleA).

        :param collection_filter: A list of strings containing the FQCN of a collection which will
            be used to limit results. This filter will take precedence over the name_filters.

        :returns: A set of tuples consisting of: role name, collection name, collection path
        )coll_filtersurrogate_or_stricterrorsrH   rI   .   )rp   r	   r   r   rO   rP   rQ   rR   rr   rk   rs   lensplit)rW   ru   collection_filterrv   
b_colldirsb_pathrP   collname	roles_dirrx   r]   r^   fqcnnscolr"   s                   rA   _find_all_collection_rolesz$RoleMixin._find_all_collection_roles   s`    )6GH
  	"F6*?@D5f=HT73Iww~~i(ZZ	2 "E %)$;$; "$&GGLLE68$T	77>>)4+3 %		5(D*A B -9 !KD'*4::c?';q'@:>**S/S$+.88RI+>(+JuX\},1IIuh6M,N)-(-		5(D2I(J!K """	"0 rf   c                    |r|j                  d      r|d   }nddi}i |d<   |rdj                  ||g      }||d<   n|}|j                         D ]#  }||   xs i }|j                  dd      |d   |<   % ||fS )	a3  Build a summary dict for a role.

        Returns a simplified role arg spec containing only the role entry points and their
        short descriptions, and the role collection name (if applicable).

        :param role: The simple role name.
        :param collection: The collection containing the role (None or empty string if N/A).
        :param meta: dictionary with galaxy information (None or empty string if N/A).
        :param argspec: The complete role argspec data dict.

        :returns: A tuple with the FQCN role name and a summary dict.
        galaxy_infodescriptionUNDOCUMENTEDentry_pointsr   r[   short_description )rl   rQ   keys)	rW   r"   r[   rI   argspecsummaryr   ep
entry_specs	            rA   _build_summaryzRoleMixin._build_summary  s     DHH]+=)G$n5G"$88Z./D$.GL!D,,. 	RB *J*4..9Lb*QGN#B'	R grf   c                ,   |rdj                  ||g      }n|}i }||d<   ||d<   d|v r|j                  |       ||fS i |d<   |j                         D ]  }|||k(  s||   xs i }	|	|d   |<    t        |d   j                               dk(  rd }||fS )Nr   rP   r[   ri   r   r   )rQ   updater   r   )
rW   r"   rP   r[   r   entry_pointr   docr   r   s
             rA   
_build_doczRoleMixin._build_doc!  s    88Z./DDF&LgJJw c{ #%Clln 9&"*;!(!2J.8C'+9 3~&++-.!3c{rf   c           
        | j                         }| j                         }|s| j                  |      }n
t               }| j	                  |      }i }||z  D ]t  \  }}}		 | j                  ||	|      }
| j                  ||	|      }d|v r'|r|d   t        j                  d|d|d   d       Y| j                  |||
|      \  }}|||<   v |S # t        $ r1}t        j                  d|dt        |      d       i }
Y d}~d}~ww xY w)	a  Return a dict describing the listing of all roles with arg specs.

        :param role_paths: A tuple of one or more role paths.

        :returns: A dict indexed by role name, with 'collection' and 'entry_points' keys per role.

        Example return:

            results = {
               'roleA': {
                  'collection': '',
                  'entry_points': {
                     'main': 'Short description for main'
                  }
               },
               'a.b.c.roleB': {
                  'collection': 'a.b.c',
                  'entry_points': {
                     'main': 'Short description for main',
                     'alternate': 'Short description for alternate entry point'
                  }
               'x.y.z.roleB': {
                  'collection': 'x.y.z',
                  'entry_points': {
                     'main': 'Short description for main',
                  }
               },
            }
        )r   zNo metadata for role (
) due to: TNri   rj   Skipping role ()_get_roles_path_get_collection_filterry   rp   r   re   rm   r:   r<   r   rn   warningr   )rW   fail_on_errors
roles_pathr   rH   	collrolesresultr"   r[   rd   rI   r@   r   r   r   s                  rA   _create_role_listzRoleMixin._create_role_list8  s+   < ))+
 779 //
;EEE33FW3X	,1I,= 	#'D*i**4JG
 ((y*EG'!!!+..OOtWU\M]$^`de //j$PMD'"F4L#	#&   dIVWLY[_`s    C	D'DDc                L   | j                         }| j                  ||      }| j                  |      }i }||z  D ]d  \  }}	}
| j                  ||
|	      }d|v r'|r|d   t        j                  d|d|d   d       E| j                  ||
|	||      \  }}|s`|||<   f |S )a  
        :param role_names: A tuple of one or more role names.
        :param role_paths: A tuple of one or more role paths.
        :param entry_point: A role entry point name for filtering.
        :param fail_on_errors: When set to False, include errors in the JSON output instead of raising errors

        :returns: A dict indexed by role name, with 'collection', 'entry_points', and 'path' keys per role.
        )ru   ri   rj   r   r   T)r   ry   r   rn   r:   r   r   )rW   
role_namesr   r   r   rH   r   r   r"   r[   rd   r   r   r   s                 rA   _create_role_doczRoleMixin._create_role_docu  s     ))+
++JZ+P333L	,1I,= 
	#'D*i((y*EG'!!!+..OOtWU\M]$^`deiWkZID#"t
	# rf   N)NN)T)NT)__name__
__module____qualname____doc__CYAML_FILENAME_EXTENSIONSrc   rk   ra   re   rn   ry   r   r   r   r   r   ).0r@   s   00rA   rD   rD   \   s     01/I/IJ!6A:J898R8RS1*Q.SVii"H2#J(T>.;zc KSs
   A(A.rD   c                >    | j                  d      st        |       } | S )N)httpz..)
startswithr!   )urls    rA   _doclinkr     s    >>.)#C(Jrf   c                   |D ]  }|t         vr6|j                         t        vr |t        j                  vrt        d|z        t        j                  r|t        v sZt        |   | z  } g|t        j                  v rt        | |      } |t         v rt        | t         |         } t        |j                            | t        d   }  | S )z$ add ascii formatting or delimiters z!Invalid format value supplied: %sr/   )		ref_styleupperSTYLEr   COLOR_CODESKeyErrorANSIBLE_NOCOLORNOCOLORr   )stringargsstyles      rA   _formatr     s      P	!ekkm5&@URSR_R_E_>FGG &0amm#VU+FiVYu%56F "'u{{}!5vuXOF!P$ Mrf   c                      e Zd ZdZdZdZ ej                  d      Z ej                  d      Z	 ej                  d      Z
 ej                  d      Z ej                  d      Z ej                  d	      Z ej                  d
      Z ej                  d      ZdZ ej                  dez         Z ej                  dez         Z ej                  dez         Z ej                  dez         Z ej                  d      Z ej                  d      Z ej                  d      ZdZ ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      Z fdZed        Zed        Z e!d        Z" fdZ# fdZ$d Z%d  Z&d! Z'ed"        Z(ed#        Z)d$ Z*d% Z+d9d&Z,d' Z-ed(        Z. fd)Z/ed*        Z0ed+        Z1ed,        Z2ed-        Z3ed.        Z4ed/        Z5d0 Z6ed1        Z7ed:d2       Z8ed3        Z9ed;d4       Z:ed<d5       Z;ed=d6       Z<d7 Z=ed>d8       Z> xZ?S )?DocCLIa   displays information on modules installed in Ansible libraries.
        It displays a terse listing of plugins and their short descriptions,
        provides a printout of their DOCUMENTATION strings,
        and it can create a short "snippet" which can be pasted into a playbook.  zansible-doc)
r+   docuriversion_addedversion_added_collectionr   now_dateplainexamples
returndocsr[   plugin_namez\bI\(([^)]+)\)z\bB\(([^)]+)\)z\bM\(([^)]+)\)z\bP\(([^#)]+)#([a-z]+)\)z\bL\(([^)]+), *([^)]+)\)z\bU\(([^)]+)\)z\bR\(([^)]+), *([^)]+)\)z\bC\(([^)]+)\)z\(((?:[^\\)]+|\\.)+)\)z\bOz\bVz\bEz\bRVz\bHORIZONTALLINE\bz\\(.)z%^([^.]+\.[^.]+\.[^#]+)#([a-z]+):(.*)$zignore:z	.. note::z.. seealso::z:\w+?:`z	.. \w+?::c                J    t         t        |   |       t               | _        y r   )superr   __init__rp   plugin_list)rW   r   	__class__s     rA   r   zDocCLI.__init__  s    fd$T*5rf   c                l    t         j                  j                  d| j                  d            }d| dS )N\1   `')r   	_UNESCAPEsubgroup)matcherr?   s     rA   _tty_ify_sem_simlezDocCLI._tty_ify_sem_simle  s1    ##E7==+;<4&{rf   c                v   t         j                  j                  d| j                  d            }d }d|v r|j	                  dd      \  }}t         j
                  j                  |      }|r4|j                  d      }|j                  d      }|j                  d      }nD|j                  t         j                        r!|t        t         j                        d  }dx}}ndx}}d }d|v r|j	                  dd      \  }}|| d| }|r+|r)|dv rdnd	}| | d
| }|dk(  r
|| d| d}d| d| dS d| dS )Nr   r   =   r   r   :)r"   r+   playbook plugin r"   , z entrypointr   z' (of rL   r   )
r   r   r   r   r   _FQCN_TYPE_PREFIX_REmatchr   _IGNORE_MARKERr   )	r   r?   valuemplugin_fqcnplugin_type
entrypointplugin_suffixplugins	            rA   _tty_ify_sem_complexzDocCLI._tty_ify_sem_complex  sc   ##E7==+;<$;**S!,KD%''--d3''!*K''!*K771:D__V223F11234D(**K+(**K+
$;#zz#q1JV1UG$D;"-1O"OBU^M#}]O1[MBFf$)?"82j\=tfF6(!,,4&{rf   c                @   | j                   j                  t        dd      |      }| j                  j                  t        dd      |      }| j                  j                  t        dd      |      }| j
                  j                  d|      }| j                  j                  d|      }| j                  j                  t        dd      |      }| j                  j                  t        dd      |      }| j                  j                  t        d	d
      |      }| j                  j                  | j                  |      }| j                  j                  | j                  |      }| j                  j                  | j                  |      }| j                  j                  | j                  |      }| j                   j                  dj#                  d      |      }| j$                  j                  d|      }| j&                  j                  t        dd      |      }| j(                  j                  d|      }| j*                  j                  d|      }t-        j                  | j
                  d |      }t-        j                  | j                  d |      }|S )Nr   r2   r-   r3   z\1 <\2>z[\1]r4   r5   z`\1'r8   z
{0}
z-------------z	See also:zNote:boldr   r   c                P    t        dt        | j                  d            z  d      S )N%sr   r6   )r   r   r   r   s    rA   <lambda>z DocCLI.tty_ify.<locals>.<lambda>  s    wux
7K/KV'T rf   c           	     t    | j                  d      dt        t        | j                  d            d      dS )Nr   z <r   r6   >)r   r   r   r   s    rA   r   z DocCLI.tty_ify.<locals>.<lambda>   s-    aggaj'(STSZSZ[\S]J^`fBg(h rf   )_ITALICr   r   _BOLD_MODULE_URL_LINK_PLUGIN_REF_CONST_SEM_OPTION_NAMEr   _SEM_OPTION_VALUEr   _SEM_ENV_VARIABLE_SEM_RET_VALUE_RULERformat_RST_SEEALSO	_RST_NOTE
_RST_ROLES_RST_DIRECTIVESre)clsr?   ts      rA   tty_ifyzDocCLI.tty_ify  s    KKOOGE;7>IIMM'%0!4KKOOGE84a8HHLL"IIMM*a(KKOOG$5x@!DHHLL.2JJNN77J7;  $$S%=%=qA!!%%c&<&<a@!!%%c&<&<a@""3#;#;Q?JJNN9++H5q9   q1MMgh7;NNtQ'##C+ FF388TVWXFF399hjklrf   c                   d}t         t        |   dd       t        j                  | j
                         t        j                  | j
                         | j
                  j                  dddd	       | j
                  j                  d
dddddj                  t              t               | j
                  j                  dddddd       | j
                  j                  dddt        j                  t        j                  d      t        j                  d       | j
                  j                         }|j                  dd d!d"#       |j                  d$d%ddd&d'd(j                  t               z         |j                  d)d*ddd+d,|z         |j                  d-d.ddd/d0|z         |j                  d1ddd2d3       | j
                  j                  d4ddd5d6       y )7Nz[A supplied argument will be used for filtering, can be a namespace or full collection name.zplugin documentation toolzWSee man pages for Ansible CLI options or website for tutorials https://docs.ansible.com)descepilogr   *Pluginr   )nargshelpmetavarz-tz--typestorer+   typezQChoose which plugin type (defaults to "module"). Available plugin types are : {0})actiondefaultdestr  choicesz-jz--json
store_trueFjson_formatzChange output into json format.)r  r  r  r  z-rz--roles-pathr   T)pathsepz0The path to the directory containing your roles.)r  r  r  r  r  z-ez--entry-pointr   z#Select the entry point for role(s).)r  r  z-sz	--snippetshow_snippetz0Show playbook snippet for these plugin types: %sr   z-Fz--list_files
list_fileszOShow plugin names and their source files without summaries (implies --list). %sz-lz--listlist_dirzList available plugins. %sz--metadata-dumpdumpzT**For internal use only** Dump json metadata for all entries, ignores other options.z--no-fail-on-errorsno_fail_on_errorsz}**For internal use only** Only used for --metadata-dump. Do not fail on errors. Report the error message in the JSON instead.)r   r   init_parseropt_helpadd_module_optionsparseradd_basedir_optionsadd_argumentr  TARGET_OPTIONSr   DEFAULT_ROLES_PATHunfrack_pathPrependListActionadd_mutually_exclusive_grouprQ   SNIPPETS)rW   r{   	exclusiver   s      rA   r$  zDocCLI.init_parser$  s   sfd',l 	( 	
 	##DKK0$$T[[1 	  s8 T  xX^'IIOP^I_)7 	! 	9 	  xeZg&G 	! 	I
 	  ~LRSRfRf&.&;&;D&I(0(B(B&X 	! 	Z KK<<>	 	t_=$I 	 	K 	t[u[i$VY]YbYbckYl$l 	 	n 	t^LRW^j$u  yD  %D 	 	EtXlEXb$@;$N 	 	P0u[a$z 	 	| 	  !6|UZat'm 	! 	nrf   c                X    t         t        |   |      }|j                  t        _        |S r   )r   r   post_process_args	verbosityr:   )rW   optionsr   s     rA   r2  zDocCLI.post_process_argsZ  s'    7@#--rf   c           
        t        d |j                         D              }t        j                  |z
  dz
  }g }g }t        j
                  d   rt        |j                               D ]  }t        ||         }|j                  d      }|d   j                  d      rN|d   dk(  rF|d	   d
v r?|d   d	d  |d<   dj                  |      }|j                  d|||t        |      |fz         |j                  d|||t        |      |fz          nt        |j                               D ]  }t        j                  ||         }	t        |	      |kD  r|	d | dz   }	|j                  d      }|d   j                  d      rP|j                  d      r?|d   d	d  |d<   dj                  |      }|j                  d|||t        |	      |	fz         |j                  d|||t        |	      |	fz          t        |      dkD  r"|j                  d       |j                  |       t        j!                  dj                  |             y )Nc              3  2   K   | ]  }t        |        y wr   r   r   xs     rA   	<genexpr>z-DocCLI.display_plugin_list.<locals>.<genexpr>d  s     6!s1v6      r   r   _r   ansibler   )builtinlegacyz%-*s %-*.*s...)ansible.builtin.zansible.legacy.z
DEPRECATED:
)maxr   r:   columnsr   CLIARGSsortedr   r   r   rQ   appendr   r   r  extendpager)
rW   resultsdisplace	linelimitr?   
deprecatedr   filenamepbreakr  s
             rA   display_plugin_listzDocCLI.display_plugin_lista  s2    6w||~66OOh.2	
 ??<( 0 
h$WV_5  c*":((-&)y2HVTUYZoMo!'ABF2J XXf-F%%mxTWX`Tack6l&lmKK69cRZm]e0f fg
h !0 `~~gfo6t9y(
+e3Dc*":((-&2C2CDk2l!'ABF2J XXf-F%%mxTWX\T]_c6d&deKK69cRViY]0^ ^_`  z?QKK(KK
# 	TYYt_%rf   c                   t        |j                               }t               }|D ].  }||   d   j                         D ]  }|j                  |        0 d}d}|rt	        d |D              }t
        j                  |z
  |z
  dz
  }g }	t        |      D ]  }||   d   rq|	j                  d|z         |	j                  d       ||   d   j                         D ]2  \  }}
t        |
      |kD  r|
d| dz   }
|	j                  d	|||
fz         4 ||	j                  d
|z          t        j                  dj                  |	             y)zDisplay all roles we can find with a valid argument specification.

        Output is: fqcn role name, entry point, short description
        r   r   c              3  2   K   | ]  }t        |        y wr   r7  r8  s     rA   r:  z2DocCLI._display_available_roles.<locals>.<genexpr>  s     ?SV?r;  r<  %s:z  specs:NrB  z    %-*s: %sr   rD  )listr   rp   rs   rE  r:   rF  rH  rI  itemsr   r   rK  rQ   )rW   	list_jsonrH   entry_point_namesr"   r   max_role_len
max_ep_lenrN  r?   r  s              rA   _display_available_roleszDocCLI._display_available_roles  sX   
 Y^^%&E 	3D(~>CCE 3!%%k23	3 
?->??JOOl2Z?!C	5M 		)D~.EDL)J')24)H)N)N)P R%K4y9,#JY/%7KK*k41P PQR
 D4K(		) 	TYYt_%rf   c                X   t        |j                               }g }|D ]E  }	 d||   v r#t        j                  d|d||   d   d       .|| j	                  |||         z  }G t        j                  dj                  |             y # t
        $ r}t        d|z  |      d }~ww xY w)Nri   zSkipping role 'z
' due to: TzRole '%srM   rD  )	rV  r   r:   r   get_role_man_textr   r   rK  rQ   )rW   	role_jsonrH   r?   r"   r@   s         rA   _display_role_doczDocCLI._display_role_doc  s    Y^^%& 	JDJio-OOtYW[_]dMe$fhlm..tYt_EE	J 	TYYt_% & J(t)<qIIJs   )BB	B)B$$B)c                 @    t        t        j                  dd            S )Nr?  zkeyword_desc.yml)r   pkgutilget_data rf   rA   _list_keywordszDocCLI._list_keywords  s    )))5GHIIrf   c           
        i }t         j                         }| D ]h  }|j                  d      rd}n
|dk(  rd}n|}	 d||   i}g |d<   t        D ]  }|t        vr<d|j                         z  }t        j                  |      }t        ||d       t        |<   |t        |   j                  v s^|d   j                  |       d|vswt        |   j                  j                  |      }	t        |	d	      ri }t        t        |	d
d      |d<   |j                  d      s|dv rd|d<   nt        |	d      rd|d<   nd|d<   dD ]  }
t        |	|
      ||
<     t        |j                               D ]  }||   	||=  |||<   k |S # t         t        f$ ri}t"        j%                  d|dt'        |             t"        j(                  dk\  r't"        j+                  t-        j.                                Y d }~d }~ww xY w)Nwith_loopasync	async_valr   
applies_tozansible.playbook.%sr  privateisar   when)untilimplicittemplatestaticexplicit)aliaspriorityzSkipping Invalid keyword 'z' specified: r   )r   re  r   
PB_OBJECTS	PB_LOADEDlower	importlibimport_modulegetattrfattributesrI  rl   r   endswithrV  r   AttributeErrorr:   r   r   r3  verboser=   r>   )r   r`   descskeyr#   kdatapobj	obj_classloaded_classfavisiblekr@   s                rA   _get_keywords_docszDocCLI._get_keywords_docs  s    %%' ;	<C~~g& %0<&c
3 ')l#& FD9,$9DJJL$H	'0'>'>y'I*1,d*K	$)D/"="==l+2248 ".!*4!<!<!@!@!IB&r95(*&.,3Bx,HE&M&//77j;P 5?j 1!(X!64<j 14>j 1 ,A F18W1EgF;FB ejjl+ %AQx'!!H% "S	m;	<z  #H- <QTV]^_V` ab$$)OOI$8$8$:;<s,   A/F,FB2F8
FG?AG::G?c                    d }t        t        j                  d         dk\  rIt        j                  d   }|D ]1  }t        j                  |      rt        dj                  |             |S )Nr   r   zGInvalid collection name (must be of the form namespace.collection): {0})r   r   rG  r   is_valid_collection_namer
   r  )rW   r{   	coll_names      rA   r   zDocCLI._get_collection_filter
  sw    wv&'1,!//&1K( D	+DDYO&'p'w'w  yB  (C  D  DD rf   c                   i }i | _         t        j                  |      }| j                         }| j                   j	                  t        ||             |dk(  r| j                  |      }|S |dk(  r:| j                   j                         D ci c]  }|| j                   |   d    }}|S | j                   j                         D ci c]  }|i  }}t               | _	        |S c c}w c c}w )NdirrY   r   )
pluginsr   _prep_loaderr   r   r   _get_plugin_list_descriptionsr   rp   r   )rW   r   contentrL  loaderr{   r  s          rA   _list_pluginszDocCLI._list_plugins  s    $$[1113LkBC e88@G  6:ll6G6G6IJq$,,q/!,,JGJ
  '+ll&7&7&9:q"u:G:"uD K:s   C$
C)c           	        t         j                  |      }i }|D ]j  }i }	 t        |||t        t        j
                  d   dkD        \  }}	}
}|s
|sddi||<   >t         j                  |||	
      }|s	 t!        |       |||<   l |S # t        $ r(}t        j                  t        |             Y d }~d }~wt        $ r}|sddt        |      z  i||<   Y d }~t        j                  t        j                                |d|dt        |      d}|rt        j                  |       nt        |      Y d }~d }~ww xY w# t        $ r}dd	t        |      z  i||<   Y d }~Nd }~ww xY w)
Nr3  r   ri   z:Missing documentation or could not parse documentation: %sr   z; missing documentation (or could not parse documentation): rD  zNo valid documentation foundz*Cannot serialize documentation as JSON: %s)r   r  r   r   r   rG  r   r:   r   r   rm   r<   r=   r>   r
   _combine_plugin_docr   )rW   r   namesfail_okr   r  plugin_docsr   r   r   r   metadatar@   msgdocss                  rA   _get_plugins_docszDocCLI._get_plugins_docs)  s   $$[1  !	'FC,;J6S^`fhw  {B  {J  {J  KV  {W  Z[  {[  <]8]J %+24R*SK'--fk3WacklD!dO
 #'KC!	'F ? ) 	!- 	,%+24ps|}~s4  +AK'I0023`kmsu~  @A  vB  COOC(&s++ )	,, ! +24`clmnco4o*pK'sB   ,B	5E		EB55ED>AD>>E	E-E((E-c                ,   t         j                  d   }t         j                  d   mt        j                  j	                  t         j                  d   d      }t        j                  j                  |      r|f|z   }|t         j                  d   fz   }|S )ao  
         Add any 'roles' subdir in playbook dir to the roles search path.
         And as a last resort, add the playbook dir itself. Order being:
           - 'roles' subdir of playbook dir
           - DEFAULT_ROLES_PATH (default in cliargs)
           - playbook dir (basedir)
         NOTE: This matches logic in RoleDefinition._load_role_path() method.
        r   basedirrH   )r   rG  rO   rP   rQ   rq   )rW   r   subdirs      rA   r   zDocCLI._get_roles_pathT  sv     __\2
??9%1WW\\'//)"<gFFww}}V$$Y3
#wy'A&CCJrf   c                &   t        t        d| z        }t        j                  d   $|j	                  t        j                  d   d       t        j                  d   r,t        j                  d   D ]  }|s|j	                  |        d|_        |S )z' return a plugint type specific loader 	%s_loaderr  NT)with_subdirmodule_path)r{  plugin_loaderr   rG  add_directory_paths)r   r  rP   s      rA   r  zDocCLI._prep_loadere  s     k(AB ??9%1  !; N??=)6 /((./
 rf   c           
     	   t         t        |           t        j                  d   }t        j                  d   j                         }t        j                  d   xs t        j                  d   }t        j                  d   xs t        j                  d   }t        t        j                  d          }t        j                  d   rd}nt        j                  d   rd	}nd }i }|r|t        _        |t        vrt        d
|z        t        j                  d   rt        }i |d<   |D ]  }	|	dk(  rL| j                  |      }
| j                  |
j                         t        j                  d   |      |d   |	<   T|	dk(  r>t        j                         }t        j                  |j                               |d   |	<   | j!                  |	d       }| j#                  |	||	dv |      |d   |	<    n|rE|dk(  rt        j                         }n|dk(  r| j                  d      }n| j!                  ||      }nt%        t        j                  d         dk(  rt        d      |dk(  r't        j                  t        j                  d         }n_|dk(  r7| j                  t        j                  d   t        j                  d   |      }n#| j#                  |t        j                  d         }|rt'        |       yg }|t(        j*                  v r|r|r| j-                  |       nVt        j                  d   rn|t.        vr!t1        ddj3                  t.              z        |j5                         D ]1  \  }}	 t        j7                  |||d         }|j9                  |       3 n|j5                         D ]W  \  }}t        jE                  |||d   |d   |d   |d         }|r|j9                  |       @t<        j?                  d|z         Y nj|dk(  r;t        j                  d   r|r| jG                  |       n>|r<| jI                  |       n*|r(t        jK                  t        jM                  |            }|r$t        jO                  dj3                  |             y# t:        $ r9}t<        j?                  djA                  |tC        |                   Y d }~nd }~ww xY w) Nr  r  r  r"  r   r!  r#  rY   r  z)Unknown or undocumentable plugin type: %sallr"   )r   r   r#   )testfilter)r  r   Fr   r   zEMissing name(s), incorrect options passed for detailed documentation.r  z>Snippets are only available for the following plugin types: %sr   r   z,Unable to construct a snippet for '{0}': {1}examplesreturnr  z.No valid documentation was retrieved from '%s'r   )(r   r   runr   rG  rx  boolr   playbook_pathsr*  r   r   r   r   re  r  r  r  r   rB   r   DOCUMENTABLE_PLUGINSrR  r/  r
   rQ   rW  format_snippetrI  
ValueErrorr:   r   r  r   format_plugin_docr\  r`  r  
_dump_yamlrK  )rW   r  r   do_jsonlistingno_failr  r  ptypesptyperH   r  plugin_namesr?   r   doc_datatextretr@   r   s                     rA   r  z
DocCLI.runx  s   fd!//),oof-335//-0KGOOF4K//,/N7??:3N7??+>??@??<(G__Z(GG5<#2n,%&QT_&_``??6"#FDK 
TF? 22'2JE)-)>)>uzz|W__]jMk  }D)>  *EDK&i'"113E)/)B)B5::<)PDK&#'#5#5eT#BL)-)?)?|^cgy^y  LS)?  *TDK&
T i',,.&--U-C))+w? 7??6*+q0)*qrri'001HI&,,W__V-DgooVcFdu|,} --k7??6;RS $KV S Da444t,,T2__^4"(2* ,8:>))H:M,N O O -1JJL 1(1&,&;&;FKQYZ_Q`&aG
 !KK01 -1JJL g("(":":6;;CE?HU_L`;CH;MxXbOc#e # KK0#OO,\_e,efg &??:.411$7**40~~f&7&7&=>RWWT]+;  * V#OO -::@&QR:TV VVs   :R$$	S&-.S!!S&c                    t        t        d| z        }|j                         }i }|D ]  }|j                  t	        |               t        |j                               S )Nr  )r{  r  _get_paths_with_contextr   r   rH  r   )r   r  pathsr  path_contexts        rA   get_all_plugins_of_typezDocCLI.get_all_plugins_of_type  sW    k(AB..0! 	6LNN<45	6glln%%rf   c           	     ^   t        t        d| z        }|j                  |ddd      }|j                  st	        dj                  | |            |j                  }|j                  }	 t        |t        t        j                  d   dkD  ||       \  }}}}|y t#        |t$        j'                  |||j(                        |j+                  dd      |j+                  dd            S # t        $ r< t        j                  t        j                                 t	        | d	|d
|d      w xY w)Nr  z.pyT)mod_typeignore_deprecatedcheck_aliasesz$unable to load {0} plugin named {1} r3  r   )r  collection_namer   r   z at zB has a documentation formatting error or is missing documentation.r   UNKNOWNr   )name	namespacer   r   )r{  r  find_plugin_with_contextresolvedr
   r  plugin_resolved_pathplugin_resolved_collectionr    r   r   rG  rm   r:   r<   r=   r>   dictr   namespace_from_plugin_filepathpackage_pathrl   )r   r   r  r   rP  r  r   __s           rA   get_plugin_metadatazDocCLI.get_plugin_metadata  s=    k(AB00u`dtx0yELL[Zefgg.. ;;	W+HoPWP_P_`kPlopPp<KYdfOCR ;;;HkSYSfSfg 3Y?''/9=	
 	
  	WKK	,,./r}  @K  MU   V  W  W	Ws   )-C' 'AD,c                   |j                  d      s|dz  }| j                  |d      }t        j                  j	                  |      d   }|j                  |d      d   j                  d      }|j                  dd      }|dk(  rd }|S )N/r   r   r   z/_r   )r}  replacerO   rP   splitextrsplitstrip)filepathr   r  rel_pathextension_freenamespace_onlyclean_nss          rA   r  z%DocCLI.namespace_from_plugin_filepath	  s    $sNG##GR0))(3A6'..{A>qAGGM!))#s3r>Hrf   c                @    |dk(  r| t         v rd|d<   nd|d<   ||||dS )Nr+   T
has_actionF)r   r  r  r  )r   )r   r   r   r   r   r  s         rA   r  zDocCLI._combine_plugin_doc  s:     ("&$(L!$)L! Yabbrf   c                
   |dk(  r;|j                  di       j                  d      rt        dj                  |             g }|dk(  rt        |      }nd|v rt	        |      }|j                  d       dj                  |      S )z9 return heavily commented plugin use to insert into play r)   r4  r   zThe {0} inventory plugin does not take YAML type config source that can be used with the "auto" plugin so a snippet cannot be created.r*   r   rD  )rl   r  r  _do_lookup_snippet_do_yaml_snippetrI  rQ   )r   r   r   r?   s       rA   r  zDocCLI.format_snippet#  s     +%#'')R*@*D*DX*N ))/9 9 ("%c*D##C(DByyrf   c                    |d   }||d<   ||d<   ||d<   	 t         j                  |||      }|S # t        $ r<}t        j	                  t        j                                t        d| z  |      d }~ww xY w)Nr[   r   r   r  z*Unable to retrieve documentation from '%s'rM   )r   get_man_textrm   r:   r<   r=   r>   r
   )	r   r   r   r   r   r  r  r?   r@   s	            rA   r  zDocCLI.format_plugin_doc7  s    l+  -O&L"J	d&&sO[ID
 	  	dKK	,,./KvVabcc	ds   / 	A47A//A4c                   i }| j                   j                         D ]  }d }t        t        | j                   |   d               }d }	 t	        |      }|t|j                  d      d   }|j                  ||j                  z         }	t        j                  D ]/  }
|	j                  |
      }	 |j                         rt	        |      }1 |rt        j                  |d|       |rt        |t               sd}n |j#                  dd      j%                         }|||<    |S # t
        $ r}|}Y d }~d }~ww xY w# t
        $ r}|}Y d }~d }~ww xY w)Nr   r   r=  z' has a documentation formatting error: r   r   zINVALID SHORT DESCRIPTION)r  r   r   r   r   rm   r   	with_namesuffixr   DOC_EXTENSIONSwith_suffixrR   r:   r   
isinstancer  rl   r  )rW   r  r  r   r   rP  docerrorr@   basebasefile	extensiondocfiler  s                rA   r  z$DocCLI._get_plugin_list_descriptionsN  sQ   ll'')  	!FCIdll6&:1&=>?HH"8,
 {||C(,#--dX__.DE!"!1!1 %I&229=G%">>+".w"7C	% QWYa bcjd3%ww24OPVVX E&MA 	!D 7   % %#$%s0   
D'.D?'	D<0D77D<?	EEEc                    g }| j                  d      D ]%  }t        |d      }||vs|j                  |       ' t        j                  j                  |      S )z; Returns a string suitable for printing of the search path F)subdirsr|   r}   )
_get_pathsr   rI  rO   r  rQ   )finderretis      rA   print_pathszDocCLI.print_pathsu  sZ    
 ""5"1 	A"78A|

1	 zzs##rf   c                F    t        | |dt              j                  d      S )Nz'')default_flow_styledefault_styleDumperrD  )r   r   rstrip)struct
flow_styles     rA   r  zDocCLI._dump_yaml  s     Jd[hippquvvrf   c           	         t         j                  dj                  | j                  d      D cg c]  }||z   	 c}            S c c}w )NrD  )r   r  rQ   r   )r?   indentlines      rA   _indent_lineszDocCLI._indent_lines  s5    ~~dii4::dCS(T4$(TUVV(Ts   Ac                8    |dk(  rd}| dk(  ry|r| d|} d| S )Nansible.builtinansible-core
historicalz of zversion rd  )r   r   s     rA   _format_version_addedzDocCLI._format_version_added  s4    #'88'5$,##*79QRM,//rf   c           
         g }| j                  d      D ]U  }t        j                  ||f|d|z  z   |dddd|}|r|j                  d|z        r||d  }|j	                  |       |}d}W dj                  |      S )Nz

r   FT)initial_indentsubsequent_indentbreak_on_hyphensbreak_long_wordsdrop_whitespacer   rD  )r   textwrapfillr   rI  rQ   )	r?   limitr	  r
  initial_extrakwargsr   	paragraphwrappeds	            rA   	warp_fillzDocCLI.warp_fill  s    F+ 	ImmIu t^VY\iViEi  ~O5:UdhtlrtG!3!3C-4G!H!-.1MM'".NM	 yy  rf   c                b
   t        |      D ]  }t        ||         }|j                  dd      }	t        |	t              st        d|	z        d}
d}|	r't        j                  rd}
||
dt        |dd	      }n%t        j                  rd
}
||
dt        |d      }d|vrt        d      | j                  d       dt        t        |      t        |      z
  t        |      z
  d      z  }|dt        |      dz   z  z   }||z   }t        |d         rt        |d   d      D ]  \  }}t        |t              st        d|d|dt        |            |dk(  rI| j                  |t         j#                  t         j%                  |      |||t        |            z          | j                  t         j#                  t         j%                  |      |||              n{t        |d   t              st        d|dt        |d               | j                  |t         j#                  t         j%                  |d         |||t        |            z          |d= g }dD ])  }||v s|j                  ||j                  |      f       + |	s|s	d|vrd |d<   i }dD ]  }||v s||   s|j                  |      D cg c]  }t        |       c}||<   t         j&                  D ]W  }||   D ]M  }t(        j*                  dkD  r0d|v r,t         j-                  |d   |j/                  dd            |d<   ||v sK||= O Y  d|v r`|d   r[g |d<   |d   D ]K  }d|vr1|d   j                  |d    d!|d    j1                  d"d
      z  d#       8|d   j                  |       M |d= |r:| j                  t         j3                  t         j5                  d$|i      |             |j                  dd       }|j                  d%d       }t        |      D ]  }|j7                  d"      rt        ||         rC| j                  t         j3                  |d&t         j5                  ||   d'(      |             f| j                  t         j3                  t         j5                  |||   i      |              |r,|s*| j                  |d)t         j-                  ||             |D ]8  \  }}| j                  ||d*       t         j9                  | |||dz   ||       :  y c c}w )+NrequiredFz8Incorrect value for 'Required', a boolean is needed.: %s  r   r   r   r   red-yellowr   zCAll (sub-)options and return values must have a 'description' fieldr   r   r   z"Expected string in description of z
 at index z, got )r	  r
  r  r	  r
  )r4  
suboptionscontainsspecr  )enviniyamlvarsr#   r   r   version_added_collecitonr  added_inclioptionr  z--%sr>  )r  r'  set_viar   : T)r  z
added in: r   )rH  r  popr  r  r
   r   r   r   rI  rE  r   r   	enumerater   r  r   r  r  IGNOREr:   r3  r  rl   r  r  r  r   
add_fields)r?   fieldsr  
opt_indentreturn_valuesbase_indentmanooptr  
opt_leadinr  inline_indentextra_indent
sub_indent	entry_idxrx   r  subkeyconfconfigitemignorer&  r   r   r  subdatas                               rA   r-  zDocCLI.add_fields  s     c	fAvay/C wwz51Hh-"#]`h#hiiJC$$!$J#.
GAvu<UV$$!$J#.
GAx<PQ C'"#hiiKKO  #s:Q'?3{CS&SUV"WWM&A
);;L&5J3}-.(1#m2Da(H M$Iu%e\:*ijluw{  }B  xC  ,D  E  E A~C&*:*:6>>%;PRW3@T^nqr~n +; +A %A B F$4$4V^^E5JEbl  AK$4  %L  MM "#m"4lC&YZ\`aderas\t'uvvC&"2"26>>#mBT3UW\+8Jfijvfw #3 #y y zM"JG AS=%%vswwv&?@A Mis6J!%I DC 	1S=S[;>776?#K4DJ#KDL"(-- 1$(L 1D&0014D9P393O3OPTUdPegkgogo  qK  M[  h\  4]Z 0%~$(L	11		1 |E
 Uu: 0Cs*U**CK6TWX^T_TgTghkmpTqKq+rsU**3/	0
 J F001B1BItCT1UWabc  GGOT:M'*ww/I4'P$ C[ b<<$s1v&KK 4 4FDUDUVYZ[V\imDUDn5oq{ |}KK 4 4V5F5F3q6{5SU_ `ab S
F<X<XYf  iA  =B  C  D#- fz6:;!!$
T8I=ZdefCc	ft $Ls   T,c                	   g }d}t         j                  dz  }t        t         j                  t        |      z
  d      }|j	                  dt        |d      d|j                  d      d       |d	   D ]V  }|d	   |   }d
}	|j                  d      rd|j                  d      z  }	|j	                  d
       |j	                  dt        |d      d|	       |j	                  d
       |j                  d      rut        |d   t              r|d   }
n|d   g}
|
D ]@  }	|j	                  dt        j                  t        j                  |	      |||      z         B |j	                  d
       |j                  d      rZ|j	                  t        dd      dt        j                  rdndz  z          t        j                  ||j                  d      ||       |j                  dd      r t         j!                  d| d| ddd       |j	                  d
       |j	                  t        d d             |d   j#                         D ]  }|j	                  d
       |j	                  t        j                  t        j                  t        d!|z  d"            |d#z
  ||             |j	                  t        j%                  t        j'                  |d   |         |              |d= d$D ]'  }||vr	|j	                  d
       t        ||   t(              r`|j	                  |j+                         d%t        j                  t        j                  ||         |t-        |      d&z   z
  |'             t        ||   t        t.        f      r7|j	                  |j+                         d%d(j1                  ||                |j	                  t        j%                  t        j'                  |j+                         ||   i      d
             * |j                  d)d      s|j	                  d
       |j	                  t        d*d             t        |d)   t(              r0|j	                  |j                  d)      j3                                *	 |j	                  t5        |j                  d)      d&d+             Y |S # t6        $ r}t9        d,|-      d.}~ww xY w)/a  Generate text for the supplied role suitable for display.

        This is similar to get_man_text(), but roles are different enough that we have
        a separate method for formatting their display.

        :param role: The role name.
        :param role_json: The JSON for the given role as returned from _create_role_doc().

        :returns: A array of text suitable for displaying to screen.
        z
          皙?F   z> ROLE: r-    (rP   rL   r   r   r   z- %szENTRY POINT: r   r   r   r  r4  Optionsr    (%s indicates it is required):r   r  
attributesFz	The role z's argument spec z contains the key "attributes", which will not be displayed by ansible-doc in the future. This was unintentionally allowed when plugin attributes were added, but the feature does not map well to role argument specs.z2.20r  )versionr  ATTRIBUTES:rU  r2      )authorr)  r   r
  r   r  	EXAMPLES:r   r   Unable to parse examples sectionrM   N)r:   rF  rE  intrI  r   rl   r  rV  r   r  r  r   r   r-  r*  rO  r   r  r  r   r   r   tuplerQ   r  r   rm   r   )rW   r"   r_  r?   r/  padr  r   r   r  r  r  r@   s                rA   r^  zDocCLI.get_role_man_text	  sr    !
oo$GOOc#h.3v)>	f@UVW$^4 ?	aKN+K8CDww*+)<!=>KKOKKV0LdSTKKOww}%c-0$7.E /0E! ODKKv'7'7t8Ledn  CM'7  (N  !N  OOBwwy!GIv69Zefevev^a  }B  :C  C  D!!$	(:E:Nww|U+""v%7} EP P #$5 #  BGM6:;\*//1 kAKKOKK 0 0PQ	S^@_1`bgjkbk  }GCM !1 !O PKK 4 4V5F5Fs<GXYZG[5\^h ij	k
 % ! bC<Bc!fl3KKAGGIv7G7GWZ[\W]H^,1SVaZ,@T^ 8H 8` !a bAu6KKAGGItyyQ7H IJ KK 4 4V5F5F	SVWXSYGZ5[]_ `ab wwz5)BGK89c*o|<KK
 3 9 9 ;<aIcggj.A!`e$fg{?	aB  % a01S^_``as   ,S	S+S&&S+c                   t        |       } t        j                  t        j                  d   fz   t        _        d}d}g }t
        j                  dz  }t        t
        j                  t        |      z
  d      }|j                  d|j                         dt        | j                  d      d	      d
| j                  d      d       t        | d   t              r| j                  d      }n| j                  d      g}|j                  d       |D ]=  }	|j                  t        j                  t        j!                  |	      |||             ? t
        j"                  dkD  r9t        j%                  | j                  dd      | j                  dd            | d<   | j'                  dd      r|j                  t        dd	d             t        | d   t               rZd| d   vrd| d   v rd| d   vr| d   d   | d   d<   	 |j                  dt(        j*                  j-                  | d   d      z          n|j                  d!| d   z         | d= | j                  d"d      r/|j                  d       |j                  t        d#d	      d$z          | j'                  d%d      r~|j                  d       |j                  t        d&d	      d't(        j2                  rd(nd)z  z          t        j5                  || j                  d%      ||t
        j"                  dk(  *       | j'                  d+d      r|j                  d       |j                  t        d,d	             | d+   j7                         D ]  }|j                  d       |j                  t        j                  t        j!                  t        d-|z  d.            |d/z
  ||             |j                  t        j9                  t        j;                  | d+   |         |              | d+= | j'                  d0d      r}|j                  d       |j                  t        d1d	             | d0   D ]F  }|j                  t        j                  t        j!                  |      |d/z
  |d d2 d3z   |             H | d0= | j'                  d4d      r|j                  d       |j                  t        d5d	             | d4   D ]  }d6|v r9|j                  t        j                  t        j!                  d7|d6   z        |d/z
  |d d2 d3z   |             |j'                  d      }||d6   j=                  d8      rd9|d6   z  }|D|j                  t        j                  t        j!                  |      |d/z
  |d:z   |d:z                |d6   j=                  d8      sd;|d6   j?                  d<d=d>      z  }|j                  t        j                  t        j!                  tA        |            |d/z
  |d:z   |             Bd?|v rod@|v rj|d@   dAvrdBnd}|j                  t        j                  t        j!                  |d@   jC                         |d|d?         |d/z
  |d d2 d3z   |             |j'                  d      }|%|d?   j=                  d8      rdC|d?   d|d@   |d<}|D|j                  t        j                  t        j!                  |      |d/z
  |d:z   |d:z                |d?   j=                  d8      sJdD|d?   j?                  d<d=d>      dE|d@   dF}|j                  t        j                  t        j!                  tA        |            |d/z
  |d:z   |             dG|v rdH|v rd|v r|j                  t        j                  t        j!                  |dG         |d/z
  |d d2 d3z   |             |j                  t        j                  t        j!                  |d         |d/z
  |d:z   |d:z                |j                  t        j                  t        j!                  |dH         |d/z
  |d:z   |d:z                dI|v sd|v s|j                  t        j                  t        j!                  dJ|dI   z        |d/z
  |d d2 d3z   |             |j                  t        j                  t        j!                  |d         |d/z
  |d:z   |d:z                |j                  t        j                  t        j!                  tA        dK|dI   z              |d/z
  |d:z   |d:z                 | d4= | j'                  dLd      r|j                  d       dMjE                  | j                  dL            }|j                  t        dNd	      dOt        j                  t        j!                  |      |dPz
  d|      z  z          tG        |       D ]@  }| |   r|t        j                  v r|j                  d       t        |j                         d	      }t        | |   tH              rR|j                  |dQt        j                  t        j!                  | |         |tK        |      d>z   z
  |R             nt        | |   t        tL        f      r)|j                  |dQdMjE                  | |                nP|j                  dS|z  t        j9                  t        j;                  | |         dtK        |      d>z   z        z          | |= C | j'                  dTd      r|j                  d       |j                  t        dUd	             t        | dT   tH              r/|j                  | j                  dT      jO                                n-	 |j                  tQ        | j                  dT      d>dV             | j'                  dXd      rg|j                  d       |j                  t        dYd	             t        j5                  || j                  dX      ||dt
        j"                  dk(  Z       |j                  d[       d[jE                  |      S # t.        $ r}
t1        d|
       d }
~
ww xY w# tR        $ r}
tU        dW|
       d }
~
ww xY w)\Nr  z        r  rA  rB  z> r   r   r   rC  rP  rL   r   r   r  r   r   r  r   r  r%  rO  FzDEPRECATED: r7   removed_at_daterG  
removed_in	Tz+Invalid deprecation documentation structurerM   r   r  z	  * note:z/ This module has a corresponding action plugin.r4  OPTIONSrE  r   r  )r2  rF  rH  rU  r2   rI  noteszNOTES:z* seealsoz	SEE ALSO:r+   z	Module %srC  z,The official documentation on the %s module.z   zcollections/%s_module.htmlr   r  r   r   r   )r+   r"   r   z"The official documentation on the zcollections/r>  z.htmlr  linkrefzAnsible documentation [%s]z/#stq=%s&stp=1requirementsr   zREQUIREMENTS:z%s
   r)  rK  z%s: r   rL  rM  rN  r   zRETURN VALUES:)r0  r2  rD  )+r  r   r,  r   rG  r:   rF  rE  rO  rI  r   r   r*  r  rV  r  r  r3  r  rl   r   r<  get_deprecated_msg_from_configr   r
   r   r-  r   r  r  r   r  r!   titlerQ   rH  r   r   rP  r  r   rm   r   )r   r  r   r/  r1  r?   rQ  r  r  r  r@   r  noter=  r   relative_urlr   reqheaders                      rA   r  zDocCLI.get_man_text^  sE    3i)@(BB
oo$GOOc#h.3k&7&7&97377=CY[a;bdgdkdklvdwxyc-($/GGM*EWW]+,EB 	BDKK(()=uU`t(  A  B	B q $::377?T`;acfcjcj  lF  HV  dW  XC
O77<'KK>?#l+T2$C,==)sS_O`B`eqy|  ~J  zK  fK69,6G	6RC%l3bKKqxx'N'NsS_O`bf'g gh D3|#445L!77<'KKOKKV47hhi779e$KKOKK	625VabararZ]x}5~~dCGGI$6zPWPaPaefPfh77<'KKOKKv67&++- gBF,,V^^GEAI{<[-\^cfg^g  yC?I - K LF001B1B3|CTUVCW1XZdef	g
 L!777E"KKOKK&12G sF,,V^^D-A519<FsOd<Rfp - r ss G779e$KKOKKV45I )ut#KK 0 0dS[n@\1] %	*Sb/D:Pdn !1 !p q"&((="9K"*tH~/H/HI[/\&TW[\dWe&e".F$4$4V^^K5P$)AIj5>Pdnqvdv %5 %x yH~001CD'Cd8nF\F\]`beghFi'iF$4$4V^^DYZfDg5h$)AIj5>Pdn %5 %p q%-4*?15m1DL^1^IdfMKK 0 0TR_M`MfMfMhjwy}  G  zH  AI  2J %	*Sb/D:Pdn !1 !p q"&((="9K"*tH~/H/HI[/\VZ[cVdfjkxfy  |I  'J".F$4$4V^^K5P$)AIj5>Pdnqvdv %5 %x yH~001CDCG>CYCYZ]_bdeCfhlmzh{'|F$4$4V^^DYZfDg5h$)AIj5>Pdn %5 %p qt^$=D;PKK 0 0V1M %	*Sb/D:Pdn !1 !p qKK 0 0]@S1T %	*u:L`jmr`r !1 !t uKK 0 0V1M %	*u:L`jmr`r !1 !t ud]}'<KK 0 0@\_cdi_j@j1k %	*Sb/D:Pdn !1 !p qKK 0 0]@S1T %	*u:L`jmr`r !1 !t uKK 0 0@UVfimnsitVt@u1v %	*u:L`jmr`r !1 !t uQ)uV I77>5)KKO))CGGN34CKK86FDTDTU[UcUcdgUhjortjt  FJ*4 EU E6 <6 6 7  	Aq6Q&--/KKOQWWY/F#a&,/0@0@PSTUPVAWY^befgbhklblYm  BL0@  1M  N  OCFT5M2		#a&0ABC FVOf.B.B6CTCTUXYZU[C\^aehijeknoeo^p.qqrA	 77?E*KKOKKV45#o.=CGGO4::<=]KK	#''/*B1af gh 77<'KKOKK 0&9:dCGGL$95*\`gngxgx|}g}Dyyo   b&'T_`aab\ ! ],-OZ[\\]s0   5r# ,s #	r>,r99r>	s
ss)FT)Fr   )r   r   r   )Fr   F)r   r   )@r   r   r   r   r  r,  r
  compiler   r   r   r   r   r   r   r   _SEM_PARAMETER_STRINGr   r  r  r  r  r   r   r   r  r  r  r	  r   staticmethodr   r   classmethodr  r$  r2  rR  r\  r`  re  r  r   r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r-  r^  r  __classcell__)r   s   @rA   r   r     sY   V
 DVF
 bjj*+GBJJ()Ebjj*+Gbjj45GBJJ23E2::'(D2::12DRZZ)*F5!rzz&+@"@A"

6,A#AB"

6,A#ABRZZ*? ?@NRZZ-.F 

8$I%2::&NON 

<(I2::o.LJ'J bjj.O!
    8  B4nl-&^ &D&  J J A AF	()V"  $jX & & 
 
6 
 
 
c 
c  &  ,%N 	$ 	$ w w W W 0 0 
! 
! ef efNSj W Wrf   r   c                   g }t         j                  | d         }| j                  d      }|r)|j                  d|z         |j                  d|z         n3|j                  d| j                  d| j                  d            z         d}d	j	                  |d
z         }t
        j                  |z
  }t        | d   j                               D ]  }| d   |   }t        |d   t              rt         j                  |d         }	n't         j                  dj                  |d               }	|j                  dd      }
t        |
t              st        d|
z        d|z  }|r6|
rd|	z  }	|j                  d|ddt         j                  |	||             |
rd}n|j                  dd      }|j                  |d|ddt         j                  |	||d              |S )Nr   r+   z
- name: %sz  %s:z# %s:r   r     # r   r4  r   r   r  F7Incorrect value for 'Required', a boolean is needed: %srU  z(required) %sz      20z   # rK  z
(required)r  None9z # r   )r
  	max_lines)r   r  rl   rI  rjustr:   rF  rH  r   r  r   rQ   r  r  r  )r   r?   mdescr+   rQ  subdentr  r3  r4  r  r  r  s               rA   r  r    s   DNN3234EWWXFLE*+Gv&' 	Gcggh@@A
Cjjq!GOOc!EC	N'')* ~)nQc-(,7>>#m"45D>>#((3}+=">?D77:u-(D)VYaabbAI&-KK63C3CD%cj3C3klm&'')V4KK!Wf6F6FtUfmyz6F6{|}-~0 Krf   c                   g }d| j                  d| j                  d            z  }g }t        | d   j                               D ]  }| d   |   }|j                  d|d|j                  dd      d	|j                  d
d             |dv r	|d|z  z  }R|j                  dd      }t	        |t
              st        d|z        |rd}n|j                  dd      }|j                  d      dv r|d|d|dz  }|d|d|z  } |dz  }|r"|j                  |       |j                  d       |j                  |       |S )Nzlookup('%s', r   r  r4  rk  (r  r   rh   r   r   )_terms_raw_listz< %s >r  Frl  z
<REQUIRED>r  rn  )r   strr   z='r   r   rL   )rl   rH  r   rI  r  r  r  rJ  )r   r?   snippetcommentr3  r4  r  r  s           rA   r  r  &  sE   D#''&/ BBGGC	N'')* 0)nQCGGFH,Esww}^`Gabc++x1~%G77:u-(D)VYaabb"Gggi0G776?//a11GAw//G+0. sNGGBKKKrf   c                .    t         j                  |        y r   )r   cli_executor)r   s    rA   rE   rE   L  s    
rf   __main__r   )Z
__future__r   ansible.clir   ry  rb  rO   os.pathr
  r  r=   ansible.plugins.loaderr  r  r  pathlibr   r?  r   r   r   ansible.cli.argumentsr   r%  ansible.collections.listr	   ansible.errorsr
   r   r   r   +ansible.module_utils.common.text.convertersr   r   'ansible.module_utils.common.collectionsr    ansible.module_utils.common.jsonr    ansible.module_utils.common.yamlr   ansible.module_utils.sixr   ansible.parsing.plugin_docsr   ansible.parsing.utils.yamlr   ansible.parsing.yaml.dumperr   ansible.plugins.listr   r   r   ansible.utils.collection_loaderr   r   2ansible.utils.collection_loader._collection_finderr   ansible.utils.colorr   ansible.utils.displayr   ansible.utils.plugin_docsr   r    r!   r:   r  r*  rv  rw  r/  r   r   COLOR_DOC_MODULECOLOR_DOC_REFERENCECOLOR_DOC_LINKCOLOR_DOC_DEPRECATEDCOLOR_DOC_CONSTANTCOLOR_DOC_PLUGINr   rB   objectrD   r   r   r   r  r  rE   r   rd  rf   rA   <module>r     s_   #    	  	   . .  "  < 9 g g J ? 6 6 1 4 0 5 - A Y ] ' ) [ [
) ''*>>9
	, 
	 	     !!$$  	Ft tn	2CS) CL"*Z#L zF rf   