
    |hj                     l   d Z ddlZddl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
ZdZdZd0dZd0dZ	 d1dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd2dZd3dZd Zd Z	 	 d4dZd Z d Z!d5d!Z"d" Z#d# Z$d$ Z%d% Z&d0d&Z'd' Z(d( Z)d) Z*d6d*Z+d+ Z,d d,efd-Z- G d. d/      Z.y)7a  Utilities for producing help strings for use in Fire CLIs.

Can produce help strings suitable for display in Fire CLIs for any type of
Python object, module, class, or function.

There are two types of informative strings: Usage and Help screens.

Usage screens are shown when the user accesses a group or accesses a command
without calling it. A Usage screen shows information about how to use that group
or command. Usage screens are typically short and show the minimal information
necessary for the user to determine how to proceed.

Help screens are shown when the user requests help with the help flag (--help).
Help screens are shown in a less-style console view, and contain detailed help
information.
    N)
completion)custom_descriptions)
decorators)
docstrings)
formatting)inspectutils)value_typesP      c                    t        j                  |       }t        | |      }t        j                  |       }t	        j
                  |       }t        | |||      }t        | ||||      }t        | |      }	t        |       rt        |||      \  }
}ng }
g }t        | |      }|||	g|
z   |z   |z   }dj                  d |D              S )a  Gets the help string for the current component, suitable for a help screen.

  Args:
    component: The component to construct the help string for.
    trace: The Fire trace of the command so far. The command executed so far
      can be extracted from this trace.
    verbose: Whether to include private members in the help screen.

  Returns:
    The full help screen as a string.
  verbose)tracer   )r   

c              3   0   K   | ]  }|
t        |   y wN)_CreateOutputSection).0sections     L/var/www/html/test/engine/venv/lib/python3.12/site-packages/fire/helptext.py	<genexpr>zHelpText.<locals>.<genexpr>X   s"      
!4 G$s   )r   Info_GetActionsGroupedByKindGetFullArgSpecr   GetMetadata_NameSection_SynopsisSection_DescriptionSectioncallable_ArgsAndFlagsSections_UsageDetailsSectionsjoin)	componentr   r   infoactions_grouped_by_kindspecmetadataname_sectionsynopsis_sectiondescription_sectionargs_and_flags_sectionsnotes_sectionsusage_details_sectionssectionss                 r   HelpTextr/   0   s    
		9	%$4YP		$	$Y	/$##I.( iUGL,%($G+It< i.CdH/+^ !N01HJ %':;  	  
  
     c                     t        ||      }t        |      }t        j                  |       r7t        t
        z
  t        |dz         z
  }t        j                  | |t              }|r| d| }d|fS |}d|fS )z&The "Name" section of the help string.include_separatorsz - NAME)_GetCurrentCommand_GetSummaryr   NeedsCustomDescriptionLINE_LENGTHSECTION_INDENTATIONlen
GetSummary)r#   r$   r   r   current_commandsummaryavailable_spacetexts           r   r   r   ^   s     'uI/' //	:!$77#o>C?D ;E EO!,,Y-8:G c'+D $ D
$r0   c                 6   t        |d      }t        |      }g }|r|j                  t        |             t	        |       r=t        ||      }|r|j                  |       n|r|j                  |j                         dj                  |      }	| d|	 }
d|
fS )z*The "Synopsis" section of the help string.T)r   r3    |  SYNOPSIS)r5   _GetPossibleActionsappend_GetPossibleActionsStringr   _GetArgsAndFlagsString	separatorr"   )r#   r%   r&   r'   r   r<   possible_actionscontinuationscallable_continuationcontinuationr?   s              r   r   r   s   s     'UtL/()@A-23CDEi24B01	 5??+M*,Al^	,$
d	r0   c                    t        j                  |       rDt        t        z
  }t        j                  | |t              }t        j
                  | |t              }nt        |      }t        |      }|xs |xs d}|rd|fS y)a5  The "Description" sections of the help string.

  Args:
    component: The component to produce the description section for.
    info: The info dict for the component of interest.

  Returns:
    Returns the description if available. If not, returns the summary.
    If neither are available, returns None.
  NDESCRIPTION)r   r7   r8   r9   GetDescriptionr;   _GetDescriptionr6   )r#   r$   r>   descriptionr=   r?   s         r   r   r      s     //	:!$77O%44Y5@BK!,,Y-8:G "$'K$G		'	'4$	4  r0   c                 :    t        | ||| |j                  v|      S )Nrequired	short_arg)_CreateFlagItemkwonlydefaults)flagdocstring_infor&   rU   s       r   _CreateKeywordOnlyFlagItemrZ      s&    	
ND4t7J7J+J
 r0   c                     | D cg c]  }|d   	 }}t        j                  |      }|D cg c]  }||   dk(  s| c}S c c}w c c}w )zGets a list of single-character flags that uniquely identify a flag.

  Args:
    flags: list of strings representing flags

  Returns:
    List of single character short flags,
    where the character occurred at the start of a flag once.
  r      )collectionsCounter)flagsfshort_flagsshort_flag_countsvs        r   _GetShortFlagsrd      sR      %%!1%+%!))+6 	>$5a$8A$=!	>> &	>s   AAAc                 Z   |j                   dt        |j                         t        |j                        z
   }|j                   t        |j                         t        |j                        z
  d }|j                  t        j
                        }g }g }| d   }|D 	cg c]  }	t        |	||       }
}	|j                  r&|
j                  t        |j                  ||             |
rN|rdnd}|dj                  |
      j                  d      f}|j                  |       |r|r|j                  d       t        |      }|D cg c]  }t        |||d|d   |v 	       }}t        |j                        }|j                  D cg c]  }t        ||||d   |v 
       }}||z   }|j                  r;g }|j                   xs g }|D cg c]  }|j                    }}t        |      }|D ]  }t#        |t$        j&                        s|j                   d   |v r"|j                   d   }d| d|j                    }nd|j                    }t        |j                   |||      }|j                  |        |r4|r!d}t)        |dd      }|j                  |       |j+                  |       t-        |j                  |      }|rd}n|rd}nd}t)        ||d      }|j                  |       |r$ddj                  |      f}|j                  |       ||fS c c}	w c c}w c c}w c c}w )z1The "Args and Flags" sections of the help string.NrY   zPOSITIONAL ARGUMENTS	ARGUMENTS
)NOTESz6You can also use flags syntax for POSITIONAL ARGUMENTSFr   rS   )rU   -z, ----)flag_stringz&The following flags are also accepted.r   indentz3Additional undocumented flags may also be accepted.zAdditional flags are accepted.zFlags are accepted.FLAGS)argsr:   defaultsgetr   ACCEPTS_POSITIONAL_ARGS_CreateArgItemvarargsrE   r"   rstriprd   rV   
kwonlyargsrZ   varkwname
isinstancer   	KwargInfo_CreateItemextend_GetArgDescription)r$   r&   r'   args_with_no_defaultsargs_with_defaultsaccepts_positional_argsr+   r,   rY   arg	arg_itemstitlearguments_sectionunique_short_argsrX   positional_flag_itemsunique_short_kwonly_flagskwonly_flag_items
flag_itemsdocumented_kwargsr_   r`   
flag_namesunique_short_flags
short_namerk   	flag_itemmessageitemrQ   flags_sections                                  r   r    r       sS   ))$HS^c$--6H%HIyyTYY#dmm2D!D!EF %LL)K)KL.(). '
 S.$/) 
 
\\t||^T: &=";E		) 4 ; ;D AB""#45!8
M %%78 %
 	 
uG00  -T__= //
 	 !
G88  %'88*	ZZ %2E"'(Q!&&(J('
3 ,	D*..	/99Q<--yy|*J<tDII;7+TYYK(+#II~t#%	 	  +, 	:7D3$)*$TZZ@KEg	0g%gwA6Dddii
34M""=1	 .	00a( )s   LLL#
L(c                 d   |\  }}}}g }|j                   r|j                  t        |             |j                   r|j                  t        |             |j                   r|j                  t        | |             |j                   r'|j                  dt	        d|j
                        f       |S )z.The usage details sections of the help string.INDEXESINDEX)membersrE   _MakeUsageDetailsSection_ValuesUsageDetailsSection_NewChoicesSectionnames)r#   r%   groupscommandsvaluesindexesr.   s          r   r!   r!     s    &=#&(FG(^^OO,V45OO,X67^^OO.y&AB__OOY 27GMM JKL	/r0   c                 @    | d   }|j                   r|j                   S d S NrY   )r=   r$   rY   s     r   r6   r6   -  s&    ().#1#9#9		CtCr0   c                 @    | d   }|j                   r|j                   S d S r   )rQ   r   s     r   rP   rP   2  s&    ().'5'A'A	#	#KtKr0   c           
      H   | j                   dt        | j                         t        | j                        z
   }| j                   t        | j                         t        | j                        z
  d }|j                  t        j
                        }g }|rz|r1|D cg c]%  }t        j                  |j                               ' }}n6|D cg c]+  }d| dt        j                  |j                                - }}|j                  |       |s| j                  s| j                  r|j                  d       | j                  rDt        j                  | j                  j                               }d| d}	|j                  |	       dj                  |      S c c}w c c}w )a-  The args and flags string for showing how to call a function.

  If positional arguments are accepted, the args will be shown as positional.
  E.g. "ARG1 ARG2 [--flag=FLAG]"

  If positional arguments are disallowed, the args will be shown with flags
  syntax.
  E.g. "--arg1=ARG1 [--flag=FLAG]"

  Args:
    spec: The full arg spec for the component to construct the args and flags
      string for.
    metadata: Metadata for the component, including whether it accepts
      positional arguments.

  Returns:
    The constructed args and flags string.
  Nrj   =<flags>[]...rB   )ro   r:   rp   rq   r   rr   r   	Underlineupperr|   rv   rw   rE   rt   r"   )
r&   r'   r~   r   r   arg_and_flag_stringsr   arg_stringsvarargs_underlinedvarargs_strings
             r   rG   rG   7  so   & ))$HS^c$--6H%HIyyTYY#dmm2D!D!EF %LL)K)KL 57  ))#))+6 7k 7
 + se1Z))#))+67
8k  , 4??djj	*	\\#--dll.@.@.BC+,D1N/	&	''%7s   *F0Fc                 h    g }| D ]*  }|j                   s|j                  |j                         , |S )z"The list of possible action kinds.)r   rE   rx   )r%   rI   action_groups      r   rD   rD   h  s<    - 1ll//01 
r0   c                 2    dj                  d | D              S )zAA help screen string listing the possible action kinds available.rA   c              3   b   K   | ]'  }t        j                  |j                                ) y wr   )r   r   r   )r   actions     r   r   z,_GetPossibleActionsString.<locals>.<genexpr>s  s)      4 ((8 4s   -/r"   )rI   s    r   rF   rF   q  s     	 4"24 
4 4r0   c                    t        dd      }t        dd      }t        dd      }t        dd	      }t        j                  | |
      }|D ]  \  }}t        |      }t	        j
                  |      r|j                  ||       t	        j                  |      r|j                  ||       t	        j                  |      sw|j                  ||        t        | t        t        f      r\| rZt        |       }	|	dk  r2|j                  dj                  d t        |	      D                     n|j                  d|	dz
          ||||gS )z8Gets lists of available actions, grouped by action kind.groupr   )rx   pluralcommandr   valuer   indexr   r   )rx   member
   , c              3   2   K   | ]  }t        |        y wr   )str)r   xs     r   r   z+_GetActionsGroupedByKind.<locals>.<genexpr>  s      FAQ Fs   )rx   z0..r\   )ActionGroupr   VisibleMembersr   r	   IsGroupAdd	IsCommandIsValuery   listtupler:   r"   range)
r#   r   r   r   r   r   r   member_namer   component_lens
             r   r   r   w  s*   GH5&i
;(GH5&WY7'%%iA'$ 2k6k"K6"jjk&j1V$llFl36"jjk&j12 	D%=)i	NMrkktyy F}1E FFkGkk]1_-.k/
(FG	,,r0   c                 6    | r| j                  |      }|S d}|S )z@Returns current command for the purpose of generating help text.r2    )
GetCommand)r   r3   r<   s      r   r5   r5     s.    
&&:L&MO 
 O	r0   c                 f    t        j                  |        dt        j                  |t               S Nrg   )r   BoldIndentr9   )rx   contents     r   r   r     s4    ood#$ %7/0 1
5 5r0   c                 T   t         t        z
  t        z
  }t        | |      }t	        j
                  | j                               }t        | |      }|rd| nd}|t        |      z
  }t	        j                  |||      }dj                  d ||fD              }t        ||t              S )a  Returns a string describing a positional argument.

  Args:
    arg: The name of the positional argument.
    docstring_info: A docstrings.DocstringInfo namedtuple with information about
      the containing function's docstring.
    spec: An instance of fire.inspectutils.FullArgSpec, containing type and
      default information about the arguments to a callable.

  Returns:
    A string to be used in constructing the help screen for the function.
  Type: r   rg   c              3   &   K   | ]	  }|s|  y wr    r   parts     r   r   z!_CreateArgItem.<locals>.<genexpr>  s     K4d$K   rl   )r8   r9   SUBSECTION_INDENTATIONr}   r   BoldUnderliner   _GetArgTyper:   EllipsisTruncater"   r{   )r   rY   r&   max_str_lengthrQ   
arg_stringarg_typer>   s           r   rs   rs     s      !447MM."37+''		4*d#($,vhZ "("S]2/!!(O^L  		KHk+BKK+	Z5K	LLr0   c                     t         t        z
  t        z
  }t        | |      }|s+t	        j
                  | j                               }d|  d| }|r|dz  }|r| d   }	d|	 d| }t        | |      }
t        | |      }|dk(  rd|
 d	}
|
rd
|
 nd}
|t        |
      z
  }t	        j                  |
||      }
|rd| nd}|t        |      z
  }t	        j                  |||      }dj                  d |
||fD              }t        ||t              S )a  Returns a string describing a flag using docstring and FullArgSpec info.

  Args:
    flag: The name of the flag.
    docstring_info: A docstrings.DocstringInfo namedtuple with information about
      the containing function's docstring.
    spec: An instance of fire.inspectutils.FullArgSpec, containing type and
     default information about the arguments to a callable.
    required: Whether the flag is required.
    flag_string: If provided, use this string for the flag, rather than
      constructing one from the flag name.
    short_arg: Whether the flag has a short variation or not.
  Returns:
    A string to be used in constructing the help screen for the function.
  rj   r   z (required)r   ri   r   Nonez	Optional[]r   r   z	Default: rg   c              3   &   K   | ]	  }|s|  y wr   r   r   s     r   r   z"_CreateFlagItem.<locals>.<genexpr>  s      tdr   rl   )r8   r9   r   r}   r   r   r   r   _GetArgDefaultr:   r   r"   r{   )rX   rY   r&   rT   rk   rU   r   rQ   flag_name_upper
short_flagr   arg_defaultr>   s                r   rV   rV     sK   0 !447MM."48+	 **4::<8OtfAo./K= KaJj\K=1Kt$(tT*+ F8*A&H$,vhZ "("S]2/!!(O^L  .9)K=)b+"S%55/!!+O  		  +{; + 
[+6L	MMr0   c                     | |j                   v r|j                   |    }	 |j                  S y# t        $ r t        |      cY S w xY w)a|  Returns a string describing the type of an argument.

  Args:
    arg: The name of the argument.
    spec: An instance of fire.inspectutils.FullArgSpec, containing type and
     default information about the arguments to a callable.
  Returns:
    A string to be used in constructing the help screen for the function, the
    empty string if the argument type is not available.
  r   )annotations__qualname__AttributeErrorrepr)r   r&   r   s      r   r   r     sU     	D$H""" 
   (^	s   , AAc                     t        |j                        }|j                  | d }t        ||j                        D ]  \  }}|| k(  st	        |      c S  | |j
                  v rt	        |j
                  |          S y)a  Returns a string describing a flag's default value.

  Args:
    flag: The name of the flag.
    spec: An instance of fire.inspectutils.FullArgSpec, containing type and
     default information about the arguments to a callable.
  Returns:
    A string to be used in constructing the help screen for the function, the
    empty string if the flag does not have a default or the default is not
    available.
  Nr   )r:   rp   ro   zipr   rW   )rX   r&   num_defaultsr   r   defaults         r   r   r     s~     T]]#,yy,0,dmm< lc7
d{'] 
T   ##D)**	r0      c                 D    |s| S t        j                  ||      }|  d| S r   )r   r   )rx   rQ   rm   s      r   r{   r{   -  s5    	K!!+v6+V 
 r0   c                     |j                   r6|j                   D ]'  }|j                  | d|  d|  fv s|j                  c S  y )N*z**)ro   rx   rQ   )rx   rY   arg_in_docstrings      r   r}   r}   5  sS    *// ,			41TFr$["A	A+++, 
r0   c                     g }| j                         D ]  \  }}t        j                  |      }|}|j                  d      }|r"t	        j
                  |      s|j                  }n>t	        j
                  |      r't	        j                  |t        t        z
  t              }nd}t        ||      }|j                  |        | j                  j                         t        | j                  j                         |      fS )z>Creates a usage details section for the provided action group.rY   N)GetItemsr   r   rq   r   r7   r=   r;   r8   r9   r{   rE   r   r   r   rx   )r   item_stringsrx   r   r$   r   rY   r=   s           r   r   r   =  s    ,"++- ldFV$DDXX./N#::6B&&g		3	3F	;#..
+ 33[Bg gtW%D 


#
#
%
\..446
E
G Gr0   c                 ~   g }|j                         D ]  \  }}~t        j                  | j                  j                        }d}d|v rH|d   }|j
                  r7|j
                  D ](  }|j                  |k(  st        ||j                        }* |t        |      }|j                  |        dt        d|      fS )zDCreates a section tuple for the values section of the usage details.NrY   VALUESVALUE)r   r   r   	__class____init__ro   rx   r{   rQ   r   rE   r   )	r#   r   value_item_strings
value_namer   	init_info
value_iteminit_docstring_infoarg_infos	            r   r   r   R  s    !??, *j%!!)"5"5">">?IJ9$%&67		!	!+00 	GH]]j($Z1E1EFJ	G z?jj)* &w0BC	DDr0   c                     t        j                  t        j                  |             }t        | dddj	                  |      z   d      S )Nz is one of the following:rg   r   r\   rl   )r   r   r   r{   r"   )rx   choicesname_formatteds      r   r   r   e  sH    ??:#7#7#=>.		12
V[[!!
 r0   c                    |r!|j                         }|j                         }nd}d}|sd}|}t        j                  |       }t	        j
                  |       }t        | |      }t        |      }	g }
|	r|
j                  t        |	             t        |      }t        |       rft        ||      }|r!|
j                  dj                  |             n|r|
j                  |j                         |j                  t!        |             |
r|ddj                  |
      z   z  }||rdndz   dz   }d	| d
dj                  |       d| S )aD  Returns usage text for the given component.

  Args:
    component: The component to determine the usage text for.
    trace: The Fire trace object containing all metadata of current execution.
    verbose: Whether to display the usage text in verbose mode.

  Returns:
    String suitable for display in an error screen.
  NFr   r   rB   rA   z -- z--helpzUsage: rg   z2
For detailed information on this command, run:
  )r   NeedsSeparatingHyphenHyphenr   r   r   r   r   rD   rE   _GetPossibleActionsUsageString_UsageAvailabilityLinesr   _GetCallableUsageItemsr"   rH   r|   _GetCallableAvailabilityLines)r#   r   r   r   needs_separating_hyphen_hyphencontinued_commandr&   r'   r%   rI   rJ   availability_linescallable_itemshelp_commands                 r   	UsageTextr  m  sf     G%*%F%F%H"G%*"	G 		$	$Y	/$##I.( 5YP()@A-78HIJ./FGi+D(;N388N34	5??+;DABuzz-8881s<  &' (	  .
 r0   c                 6    | rdj                  |       }d| dS y )N|<>r   )rI   actions_strs     r   r	  r	    s&    ((+,K{m1	r0   c                     g }| D ]E  }|j                   st        d|j                   d|j                        }|j	                  |       G |S )Nz
available :)headeritems)r   _CreateAvailabilityLiner   r   rE   )r%   r  r   availability_lines       r   r
  r
    s`    - 3l1l112!4""  123 
r0   c                    | j                   dt        | j                         t        | j                        z
   }| j                   t        | j                         t        | j                        z
  d }|j                  t        j
                        }|s$|D cg c]  }d| d|j                           }}n|D cg c]  }|j                          }}|s| j                  s| j                  r|j                  d       | j                  r-|j                  d| j                  j                          d       |S c c}w c c}w )zBA list of elements that comprise the usage summary for a callable.Nrj   r   r   r   r   )ro   r:   rp   rq   r   rr   r   rv   rw   rE   rt   )r&   r'   r~   r   r   r   r  s          r   r  r    s   ))$HS^c$--6H%HIyyTYY#dmm2D!D!EF %LL)K)KL	 -/ #a		}% /E / %::SSYY[:E: 4??djj	LL	\\	LL1T\\'')*$/0	,/ ;s   D9:D>c                 2      fd j                   D        S )Nc              3   D   K   | ]  }|j                   v k7  r|  y wr   )rW   )r   rX   rT   r&   s     r   r   z(_KeywordOnlyArguments.<locals>.<genexpr>  s+      
84$$"5"556  
8s    )rv   )r&   rT   s   ``r   _KeywordOnlyArgumentsr!    s    
84?? 
8 8r0   c                    | j                   t        | j                         t        | j                        z
  d }t        j                  |t        | d            D cg c]  }d| 	 }}t        | d      D cg c]  }d| 	 }}g }|r|j                  t        d|d             |r|j                  t        d	|d             | j                  r%|s|rd
nd}|j                  t        |g d             |S c c}w c c}w )zHThe list of availability lines for a callable for use in a usage string.NF)rT   rj   Tzoptional flags:r   )r  r  header_indentzrequired flags:zadditional flags are acceptedzflags are accepted)	ro   r:   rp   	itertoolschainr!  rE   r  rw   )r&   r   rX   optional_flagsrequired_flagsr  additional_flagss          r   r  r    s(   yyTYY#dmm2D!D!EF -6OO/uE-G HDbK H. H 4D4H4&k. 
 '8./	12 '8./	12 
ZZ)^ 8,  '7r./	12 
/Hs   C:9C?   c                     ||z
  }dj                  t        j                  ||            }t        j                  ||      }t        j                  | |      }||t	        |      d  z   dz   S )Nrg   )width)spaces)r"   r   WrappedJoinr   r:   )	r  r  r#  items_indentline_lengthitems_width
items_textindented_items_textindented_headers	            r   r  r    sl     l*+yy//[IJ*"))*\J%%f]C/	.s?/C/DE	E	LLr0   c                   $    e Zd ZdZd ZddZd Zy)r   z$A group of actions of the same kind.c                 <    || _         || _        g | _        g | _        y r   )rx   r   r   r   )selfrx   r   s      r   r   zActionGroup.__init__  s    DIDKDJDLr0   Nc                 p    | j                   j                  |       | j                  j                  |       y r   )r   rE   r   )r6  rx   r   s      r   r   zActionGroup.Add  s&    JJdLLr0   c                 B    t        | j                  | j                        S r   )r   r   r   )r6  s    r   r   zActionGroup.GetItems  s    tzz4<<((r0   r   )__name__
__module__r   __doc__r   r   r   r   r0   r   r   r     s    , )r0   r   )NFr   )F)NT)FNF)r   )T)/r;  r]   r$  firer   r   r   r   r   r   r	   r8   r9   r   r/   r   r   r   rZ   rd   r    r!   r6   rP   rG   rD   rF   r   r5   r   rs   rV   r   r   r{   r}   r   r   r   r  r	  r
  r  r!  r  r  r   r   r0   r   <module>r=     s  "    $       +\,  08?]1@"D
L
.(b4-65
MB :?05;N|..G*E&9x	08
@ +,"(3M) )r0   