
    Vh8H                        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
Z d dlZd dlmZ d dlmZ d dlmZmZ d dlm
Z
 d dlmZ  G d d	ej.                        Z G d
 dej2                        Z G d dej4                        Z G d dej4                        Z G d dej4                        Zd Zd)dZd Z d Z!d Z"d*dZ#d+dZ$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d  Z,d! Z-d" Z.d# Z/d*d$Z0d% Z1d& Z2d' Z3d( Z4y),    )annotationsN)__version__)	constants)	to_native)HAS_LIBYAML	yaml_load)unfrackpathc                       e Zd Z fdZ xZS )SortingHelpFormatterc                l    t        |t        j                  d            }t        t        |   |       y )Noption_strings)key)sortedoperator
attrgettersuperr   add_arguments)selfactions	__class__s     T/home/dcms/DCMS/lib/python3.12/site-packages/ansible/cli/arguments/option_helpers.pyr   z"SortingHelpFormatter.add_arguments   s+    h&9&9:J&KL"D7@    )__name__
__module____qualname__r   __classcell__r   s   @r   r   r      s    A Ar   r   c                       e Zd Z fdZ xZS )ArgumentParserc                    |j                  d      }|j                  d      }|r!|ddddt        hv r|j                  d       d}||d<   t        |   |i |S )	Nactionhelpappendappend_constcountextend.z0. This argument may be specified multiple times.)getPrependListActionrstripr   add_argument)r   argskwargsr!   r"   r   s        r   r+   zArgumentParser.add_argument"   sj    H%zz&!Fx(L]^^kk#&''WXDvw#T4V44r   )r   r   r   r+   r   r   s   @r   r   r   !   s    5 5r   r   c                      e Zd ZddZy)AnsibleVersionNc                v    t        t        t        |d                  }t        |       |j	                          y )Nprog)r   versiongetattrprintexit)r   parser	namespacevaluesoption_stringansible_versions         r   __call__zAnsibleVersion.__call__,   s)    #GGFF,C$DEor   N)r   r   r   r;    r   r   r/   r/   +   s    r   r/   c                  (     e Zd Zd fd	ZddZ xZS )UnrecognizedArgumentc	           	     :    t         t        |   |||||||       y )N)r   destnargsconstdefaultrequiredr"   )r   r?   __init__)
r   r   rA   rC   rD   rE   r"   metavarrB   r   s
            r   rF   zUnrecognizedArgument.__init__3   s,    "D2.W[chpu;BX\` 	3 	br   c                ,    |j                  d|z         y )Nzunrecognized arguments: %s)error)r   r6   r7   r8   r9   s        r   r;   zUnrecognizedArgument.__call__7   s    1MABr   )TNFNNr   r<   )r   r   r   rF   r;   r   r   s   @r   r?   r?   2   s    bCr   r?   c                  0     e Zd ZdZ	 	 d fd	ZddZ xZS )r)   znA near clone of ``argparse._AppendAction``, but designed to prepend list values
    instead of appending.
    c                    |dk(  rt        d      |/|t        j                  k7  rt        dt        j                  z        t        t        |   |||||||||	|

       y )Nr   znargs for append actions must be > 0; if arg strings are not supplying the value to append, the append const action may be more appropriatez nargs must be %r to supply const)
r   rA   rB   rC   rD   typechoicesrE   r"   rG   )
ValueErrorargparseOPTIONALr   r)   rF   )r   r   rA   rB   rC   rD   rL   rM   rE   r"   rG   r   s              r   rF   zPrependListAction.__init__?   s~    A: O P P (*;*;!;?(BSBSSTT/) 	0 	
r   c                    t        j                   t        || j                  g             }||dd t        || j                  |       y )Nr   )copyensure_valuerA   setattr)r   r6   r7   r8   r9   itemss         r   r;   zPrependListAction.__call__T   s8    		,y$))R@Aa
	499e,r   )NNNNNFNNr<   )r   r   r   __doc__rF   r;   r   r   s   @r   r)   r)   ;   s     Y]BF
*-r   r)   c                N    t        | |d       t        | ||       t        | |      S r<   )r3   rT   )r7   namevalues      r   rS   rS   Z   s*    y$%-	4'9d##r   c                      fd}|S )z=Turn an Option's data into a single path in Ansible locationsc                    r;| j                  t        j                        D cg c]  }|st        |       c}S | dk(  r| S t        |       S c c}w )Nfollow-)splitospathsepr	   )rY   xr]   ra   s     r   innerzunfrack_path.<locals>.innere   sM    ;@;;rzz;RXaVWK&1XXC<L500 Ys
   AAr=   )ra   r]   rc   s   `` r   unfrack_pathrd   c   s    1 Lr   c                      fd}|S )Nc                L    | j                        rt        | dd        z   S | S )N   )
startswithr	   )rY   beacons    r   rc   z!maybe_unfrack_path.<locals>.innerr   s,    F#Kab	222r   r=   )ri   rc   s   ` r   maybe_unfrack_pathrj   p   s     Lr   c           	     X   d}t         j                  j                  |       rJt         j                  j                  |       rt	 t	        |       5 }t        |      j                  d      }ddd       t         j                  j                        r|} n#t         j                  j                  | dd |      } t	        t         j                  j                  | d            5 }|j                         j                  d      }|j                  d      r$t         j                  j                  | |dd       }nd}ddd       rjt         j                  j                  |      rKd	j                  j                  d	      d
d       }t	        |      5 }|j                         dd }ddd       n'dd }d}t         j                  j                  | d      }t        j                   t        j"                  |      j$                        }t        j&                  dk(  rt        j(                  }	nt        j*                  }	dj-                  |t        j.                  d|      t1        |	dz              }|S d}|S # 1 sw Y   
xY w# t        t        f$ r Y yw xY w# 1 sw Y   _xY w# 1 sw Y   xY w)zC returns a string containing git branch, commit id and commit date Ngitdir HEAD
zref:   /   
   zdetached HEADr   z)({0} {1}) last updated {2} (GMT {3:+04d})z%Y/%m/%d %H:%M:%Si)r`   pathexistsisfileopenr   r(   isabsjoinIOErrorAttributeErrorreadliner*   rh   r_   time	localtimestatst_mtimedaylighttimezonealtzoneformatstrftimeint)
	repo_pathresultfrl   linebranch_pathbranchcommitdateoffsets
             r   _git_repo_infor   y   s>   F	ww~~i 77>>)$	)_ 8&q\--h7F8 77==( &I "Ys^V DI "'',,y&12 	#a::<&&t,Dv& ggll9d12h?"	# 277>>+6XXdjjoab12Fk" +acr*+ + #2YF$F'',,y&9K~~bggk2;;<==A]]F\\F<CCFFTXTaTabuw{T|  B  CI  LO  CO  P  Q M MC8 8 ^, 	# 	#+ +sD   I> I1)AI> AJJ 1I;6I> >JJJ J)c            	        t         j                  j                  t         j                  j                  t         j                  j	                  t
              dddd            } t         j                  j                  | d      }t        |      S )Nz..z.git)r`   ru   normpathrz   dirname__file__r   )basedirr   s     r   _gitinfor      sY    ggrww||BGGOOH,EtTSWY]^_GWf-I)$$r   c                   | rdj                  | t              g}nt        g}t               }|rdj                  |d   |      |d<   |j                  dt        j
                  z         t        j                  d}nt        j                  }|j                  d|z         |j                  ddj                  t        j                        z         |j                  d	dj                  t        j                        z         |j                  d
t        j                  d   z         |j                  ddj                  t        j                  j                               dt        t        j                         d       |j                  dt"        z         |j                  dt$        z         dj                  |      S )z return ansible version z{0} [core {1}]z{0} {1}r   z  config file = %szDefault w/o overridesz$  configured module search path = %sz%  ansible python module location = %s:z"  ansible collection location = %sz  executable location = %sz  python version = rn   z ()z  jinja version = %sz  libyaml = %srp   )r   r   r   r#   CCONFIG_FILEDEFAULT_MODULE_PATHrz   ansible__path__COLLECTIONS_PATHSsysargvr2   
splitlinesr   
executable
j2_versionr   )r1   r   gitinfocpaths       r   r2   r2      sL   "))$<=jG$$VAY8q	
MM&67$'%%
MM85@A
MM9CHHWEUEU<VVW
MM6!BUBU9VVW
MM.!<=
MM"''#++:P:P:R2SU^_b_m_mUnop
MM(:56
MM"[0199Vr   c                z    t        | t        ||d      }d}|j                  dt        d|       t	        |       |S )z:
    Create an options parser for all ansible scripts
    resolve)r1   formatter_classepilogdescriptionconflict_handlerzshow program's version number, config file location, configured module search path, module location, executable location and exitz	--versionr   )r!   rB   r"   )r   r   r+   r/   add_verbosity_options)r1   usagedescr   r6   version_helps         r   create_base_parserr      sK    
 ,"FDL N!,W&!Mr   c                N    | j                  dddt        j                  dd       y)zAdd options for verbosityz-vz	--verbose	verbosityr%   zCauses Ansible to print more debug messages. Adding multiple -v will increase the verbosity, the builtin plugins currently evaluate up to -vvvvvv. A reasonable level to start is -vvv, connection debugging might require -vvvv.rA   rD   r!   r"   N)r+   r   DEFAULT_VERBOSITYr6   s    r   r   r      s-    
kQEXEXahI  Jr   c           	         | j                  ddt        j                  t        ddt        j                  z         | j                  dddt        d	d
       y)z5Add options for commands which can launch async tasksz-Pz--pollpoll_intervalz.set the poll interval if using -B (default=%s)rD   rL   rA   r"   z-Bz--backgroundsecondsr   z9run asynchronously, failing after X seconds (default=N/A))rA   rL   rD   r"   N)r+   r   DEFAULT_POLL_INTERVALr   r   s    r   add_async_optionsr      sX    
h0G0GcXgMPQPgPgg  i
n93PQX  Zr   c           	     ^    | j                  dt        j                  dddt                      y)z9Add options for commands which can set a playbook basedirz--playbook-dirr   storezSince this tool does not use playbooks, use this as a substitute playbook directory. This sets the relative path for many features including roles/ group_vars/ etc.)rD   rA   r!   r"   rL   N)r+   r   PLAYBOOK_DIRrd   r   s    r   add_basedir_optionsr      s.    
(!..yY`o)^  -r   c                |    | j                  dddddd       | j                  dd	t        j                  d
dd       y)zKAdd options for commands which can run with diagnostic information of tasksz-Cz--checkFcheck
store_truezRdon't make any changes; instead, try to predict some of the changes that may occurrD   rA   r!   r"   z-Dz--diffdiffzhwhen changing (small) files and templates, show the differences in those files; works great with --checkN)r+   r   DIFF_ALWAYSr   s    r   add_check_optionsr      sL    
iW\q  s
hFS_@  Ar   c           	     >   | j                  dd      }|j                  ddt        j                  ddt	                      |j                  dd	t        j
                  d
dt        j
                  z         |j                  dddt        j                  dt        j                  z         |j                  dddt        dd       |j                  dddd       |j                  dddd       |j                  dddd        |j                  d!dd"d#       | j                  |       | j                         }|j                  d$d%t        j                  d&d'd()       |j                  d*d+t        j                  d,d-t	               d./       | j                  |       y)0z@Add options for commands which need to connection to other hostszConnection Optionsz+control as whom and how to connect to hostsz--private-keyz
--key-fileprivate_key_filez,use this file to authenticate the connection)rD   rA   r"   rL   z-uz--userremote_userz!connect as this user (default=%s)rD   rA   r"   z-cz--connection
connectionz#connection type to use (default=%s)rA   rD   r"   z-Tz	--timeoutNtimeoutzJoverride the connection timeout in seconds (default depends on connection)r   z--ssh-common-argsssh_common_argszDspecify common arguments to pass to sftp/scp/ssh (e.g. ProxyCommand)z--sftp-extra-argssftp_extra_argsz:specify extra arguments to pass to sftp only (e.g. -f, -l)z--scp-extra-argsscp_extra_argsz5specify extra arguments to pass to scp only (e.g. -l)z--ssh-extra-argsssh_extra_argsz5specify extra arguments to pass to ssh only (e.g. -R)z-kz
--ask-passask_passr   zask for connection passwordr   z--connection-password-filez--conn-pass-fileconnection_password_filezConnection password filer   rD   rA   r"   rL   r!   )add_argument_groupr+   r   DEFAULT_PRIVATE_KEY_FILErd   DEFAULT_REMOTE_USERDEFAULT_TRANSPORTr   add_mutually_exclusive_groupDEFAULT_ASK_PASSCONNECTION_PASSWORD_FILE)r6   connect_groupconnect_password_groups      r   add_connect_optionsr      s   --.BDqrMaF`F`gy$RYeYg  itXq7L7LS`$G!J_J_$_  at^,PQPcPc$IAL_L_$_  at[$Sy$p  r 2DGX$j  l2DGX$`  b14FV$[  ]14FV$[  ] m,#@@B''lADVDV]gp|-J ( L''(DFXbcb|b|  D^-Glnel ( n 45r   c           	     x    | j                  dddt        j                  t        dt        j                  z         y)z7Add options for commands that can fork worker processesz-fz--forksforksz8specify number of parallel processes to use (default=%s))rA   rD   rL   r"   N)r+   r   DEFAULT_FORKSr   r   s    r   add_fork_optionsr     s4    
igqUXWZ[ZiZii  kr   c                    | j                  dddddd       | j                  dd	d
d       | j                  ddt        j                  dd       y)z/Add options for commands that utilize inventoryz-iz--inventoryz--inventory-file	inventoryr#   zXspecify inventory host path or comma separated host list. --inventory-file is deprecatedrA   r!   r"   z--list-hosts	listhostsr   z@outputs a list of matching hosts; does not execute anything elsez-lz--limitsubsetz5further limit selected hosts to an additional patternr   N)r+   r   DEFAULT_SUBSETr   s    r   add_inventory_optionsr   $  sg    
m-?kZbw  y
[_  a
i1A1AT  Vr   c                v    | j                  dt        j                  ddd       | j                  dddd	       y
)zJAdd options for commands which can launch meta tasks from the command linez--force-handlersforce_handlersr   z!run handlers even if a task failsr   z--flush-cacheflush_cachez0clear the fact cache for every host in inventoryr   N)r+   r   DEFAULT_FORCE_HANDLERSr   s    r   add_meta_optionsr   .  sG    
*A4L4LSclx@  B
mLO  Qr   c           
         t         j                  j                  d      j                  dd      }| j	                  ddddd|z  t        d	
      t               y)z*Add options for commands that load modulesr   rD   rn   z-Mz--module-pathmodule_pathNz>prepend colon-separated path(s) to module library (default=%s)T)ra   )rA   rD   r"   rL   r!   )r   configget_configuration_definitionr(   r+   rd   r)   )r6   r   s     r   add_module_optionsr   6  sV    ((778MNRRS\^`aK
oM4]`kk)$7@Q  Sr   c                \    | j                  ddddd       | j                  ddd	d
d       y
)z6Add options for commands which can change their outputz-oz
--one-lineone_liner   zcondense outputr   -tz--treetreeNzlog output to this directoryr   )r+   r   s    r   add_output_optionsr   >  s>    
lL.  0
hVT;  =r   c                n   | j                  dd      }|j                  ddt        j                  ddd       |j                  d	d
t        j                  dt        j                  z  dz          |j                  dddt
        dt        j                  z         | j                  |       t        |        y)z
    Add options for commands which can run tasks as another user

    Note that this includes the options from add_runas_prompt_options().  Only one of these
    functions should be used.
    zPrivilege Escalation Optionsz8control how and which user you become as on target hostsz-bz--becomer   becomez>run operations with become (does not imply password prompting))rD   r!   rA   r"   z--become-methodbecome_methodz/privilege escalation method to use (default=%s)z7, use `ansible-doc -t become -l` to list valid choices.r   z--become-userNbecome_userz(run operations as this user (default=%s))rD   rA   rL   r"   )r   r+   r   DEFAULT_BECOMEDEFAULT_BECOME_METHODstrDEFAULT_BECOME_USERadd_runas_prompt_options)r6   runas_groups     r   add_runas_optionsr  F  s     ++,J  MG  HK T:q7G7GP\ck"b  d._aNeNe"SVWVmVm"m"[#\  ] _dUX"LqOdOd"d  f k*V$r   c           	        || j                  |       | j                         }|j                  ddddt        j                  d       |j                  dd	t        j
                  d
dt               d       | j                  |       y)z
    Add options for commands which need to prompt for privilege escalation credentials

    Note that add_runas_options() includes these options already.  Only one of the two functions
    should be used.
    Nz-Kz--ask-become-passbecome_ask_passr   z%ask for privilege escalation password)rA   r!   rD   r"   z--become-password-filez--become-pass-filebecome_password_filezBecome password filer   r   )r   r   r+   r   DEFAULT_BECOME_ASK_PASSBECOME_PASSWORD_FILErd   )r6   r  runas_pass_groups      r   r  r  ]  s     !!+.::<!!$(;BS\h*+*C*C'N " P !!":<PZ[ZpZp  xN'=LN[b " d ./r   c           	     F    | j                  ddddt        d      dg        y)	z(Add options for commands that run a taskz-ez--extra-vars
extra_varsr#   @zNset additional variables as key=value or YAML/JSON, if filename prepend with @)rA   r!   rL   r"   rD   N)r+   rj   r   s    r   add_runtask_optionsr  r  s-    
n<WijmWnmwy  {r   c                V    | j                  dt        ddt        j                  d       y)z;Add options for commands that run a task w/o a defined playz--task-timeouttask_timeoutr   z<set task timeout limit in seconds, must be positive integer.)rL   rA   r!   rD   r"   N)r+   r   r   TASK_TIMEOUTr   s    r   add_tasknoplay_optionsr  x  s,    
(sPWabaoao[  ]r   c                    | j                  dddt        j                  dd       | j                  ddt        j                  dd	       y
)z8Add options for commands which can run a subset of tasksr   z--tagstagsr#   z1only run plays and tasks tagged with these valuesr   z--skip-tags	skip_tagsz=only run plays and tasks whose tags do not match these valuesN)r+   r   TAGS_RUN	TAGS_SKIPr   s    r   add_subset_optionsr  ~  sL    
hVQZZPXP  R
KU]\  ^r   c           
         | j                  dg ddt        d       | j                         }|j                  dddt        j                  d	d
d       |j                  ddg ddt        d      d       y)z#Add options for loading vault filesz
--vault-id	vault_idsr#   zthe vault identity to use)rD   rA   r!   rL   r"   z-Jz--ask-vault-passwordz--ask-vault-passask_vault_passr   zask for vault passwordr   z--vault-password-filez--vault-pass-filevault_password_fileszvault password fileFr\   r   N)r+   r  r   r   DEFAULT_ASK_VAULT_PASSrd   )r6   
base_groups     r   add_vault_optionsr     s    
b{8Z]8  :446JD"8:LVWVnVn  vF  O[!9  ;35HRT[q!6\QV=W`h  jr   )FTr<   )rn   NN)5
__future__r   rR   r   rO   r`   os.pathr   r~   jinja2r   r   r   r   r   +ansible.module_utils.common.text.convertersr    ansible.module_utils.common.yamlr   r   ansible.releaseansible.utils.pathr	   HelpFormatterr   r   Actionr/   r?   r)   rS   rd   rj   r   r   r2   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r=   r   r   <module>r*     s   #    	  
  ,  " A C ' *A811 A5X,, 5X__ C8?? C- ->$
(V%:(JZ-A6DkVQS=%.0*{]^jr   