
    R"              	          S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKr " S S\R                  " \R                  \5      5      r " S	 S
\5      rS rSrSS jrS rS rSS\S\S\\S4   4S jjrSS jrSS jrS rS rSS jrg)z@Utilities for adding help text for flags with an argparser type.    )absolute_import)division)unicode_literalsN)Unionc                       \ rS rSrSr\\R                  S 5       5       r\R                  S 5       r	\R                  S 5       r
\R                  S 5       rSrg)	ArgTypeUsage   zEInterface for flags types that need to provide additional usage info.c                     g)zWhether the argument is hidden.N selfs    5lib/googlecloudsdk/calliope/arg_parsers_usage_text.pyhiddenArgTypeUsage.hidden           c                     g)z,Returns the metavar for flag with type self.Nr   )r   is_custom_metavarmetavars      r   GetUsageMetavarArgTypeUsage.GetUsageMetavar#   r   r   c                     g)z=Returns the example user input value for flag with type self.Nr   )r   	shorthands     r   GetUsageExampleArgTypeUsage.GetUsageExample'   r   r   c                     g)z.Returns the help text for flag with type self.Nr   )r   
field_namerequired	flag_names       r   GetUsageHelpTextArgTypeUsage.GetUsageHelpText+   r   r   r   N)__name__
__module____qualname____firstlineno____doc__propertyabcabstractmethodr   r   r   r    __static_attributes__r   r   r   r   r      su    M*  * 7 7 H H 9 9r   r   c                   ^   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       rS r	S r
S rS	rU =r$ )
DefaultArgTypeWrapper0   zBase class for processing arg_type output but maintaining usage help text.

Attributes:
  arg_type: type function used to parse input string into correct type ie
    ArgObject(value_type=int, repeating=true), int, bool, etc
c                 6   > [         [        U ]  5         Xl        g N)superr,   __init__arg_type)r   r2   	__class__s     r   r1   DefaultArgTypeWrapper.__init__8   s    	
/1Mr   c                 6    [        U R                  [        5      $ r/   )
isinstancer2   r   r   s    r   _is_usage_type$DefaultArgTypeWrapper._is_usage_type<   s    dmm\22r   c                 R    U R                   (       a  U R                  R                  $ g r/   )r7   r2   r   r   s    r   r   DefaultArgTypeWrapper.hidden@   s    ]]!!!r   c                 ^    U R                   (       a  U R                  R                  " U0 UD6$ g)z,Forwards default usage metavar for arg_type.N)r7   r2   r   r   argskwargss      r   r   %DefaultArgTypeWrapper.GetUsageMetavarG   (    ]]**D;F;;r   c                 ^    U R                   (       a  U R                  R                  " U0 UD6$ g)z,Forwards default usage example for arg_type.N)r7   r2   r   r<   s      r   r   %DefaultArgTypeWrapper.GetUsageExampleN   r@   r   c                 ^    U R                   (       a  U R                  R                  " U0 UD6$ g)z(Forwards default help text for arg_type.N)r7   r2   r    r<   s      r   r    &DefaultArgTypeWrapper.GetUsageHelpTextU   s(    ]]++T<V<<r   r2   )r"   r#   r$   r%   r&   r1   r'   r7   r   r   r   r    r*   __classcell__)r3   s   @r   r,   r,   0   sI     3 3   r   r,   c                 Z    [        U [        5      =(       a    U R                  =(       d    S$ )zReturns whether arg_type is hidden.

Args:
  arg_type: Callable, arg type that may contain hidden attribute

Returns:
  bool, whether the type is considered hidden
F)r6   r   r   rE   s    r   IsHiddenrH   ]   s     X|
,
@	JUJr   z::
c                 F    SU-  nU R                  [        U[        -   5      $ )z3Tabs over all lines in text using ascii doc syntax.:)replaceASCII_INDENT)textdepthadditional_tabss      r   IndentAsciiDocrP   l   s!    %K/	lOl$B	CCr   c                 ~    U (       d  g[        U [        5      (       a  U $ U [        L a  gU [        L a  gU [        L a  gg)zReturns a user friendly name of a primitive arg_type.

Args:
  arg_type: type | str | None, expected user input type

Returns:
  String representation of the type
Nintfloatbooleanstring)r6   strrR   rS   boolrE   s    r   _FormatBasicTypeStrrX   r   sC     
#O _ 
r   c                 \    U R                  5       nUR                  S5      (       a  U$ US-   $ )z5Adds punctuation to text if it doesn't already exist..)rstripendswith)rM   
clean_texts     r   
_Punctuater^      s/    {{}*r   rM   ignorereturnc                 T    U (       a  U(       a  U $ U S   R                  5       U SS -   $ )zCapitalizes the first letter of text.

Args:
  text: The text to capitalize.
  ignore: Whether to ignore the capitalization request.

Returns:
  The capitalized text.
r      N)upper)rM   r_   s     r   _Capitalizerd      s)     
K	a48	##r   c                     U(       a  [        U5      nO/U (       a  [        SR                  U 5      U5      nO[        SU5      nU(       a  SR                  U5      $ U$ )a  Defaults and formats specific attribute of help text.

Args:
  field_name: None | str, attribute that is being set by flag
  required: bool, whether the flag is required
  help_text: None | str, text that describes the flag

Returns:
  help text formatted as `{type} {required}, {help}`
zsets `{}` value.zsets value.zRequired, {})r^   rd   format)r   r   	help_textdefaulted_help_texts       r   FormatHelpTextri      sZ     $Y/%!!*-x &mX>  !455r   c                     SU;   a  SR                  X5      nOSR                  X5      nU(       a  SR                  US9$ SR                  U5      $ )zFormats flag in markdown code snippet.

Args:
  arg_name: str, name of the flag in snippet
  arg_value: str, flag value in snippet
  append: bool, whether to use append syntax for flag

Returns:
  markdown string of example user input
 z{}='{}'z{}={}z```

{input} {input}

```)inputz```

{}

```)rf   )arg_name	arg_valueappendexample_flags       r   FormatCodeSnippetrq      sR     	I##H8L>>(6L*111EE$$\22r   c                    U (       d  g[        U [        5      (       a  U R                  US9nO[        U 5      n[        U [        5      nU[        [        5      :H  nU(       d  U(       d  U(       a  SR                  U5      $ U$ )zGets an example input value for flag of arg_type.

Args:
  arg_type: Callable[[str], Any] | str | None, expected user input type
  shorthand: bool, whether to display example in shorthand

Returns:
  string representation of user input for type arg_type
N)r   z"{}")r6   r   r   rX   rV   rf   )r2   r   arg_stris_string_literalis_string_types        r   _GetNestedValueExamplerv      sm     
,''&&&;G!(+G 3/1#66.	)^==!!Nr   c                     [        X5      n[        X5      n[        U 5      (       d  [        U5      (       a  gU(       a  U(       d  U=(       d    U$ U(       a  US:w  a  U SU 3$ U$ U SU 3$ )a  Formats example key-value input for flag of arg_type.

If key_type and value_type are callable types str, returns

  string=string (shorthand) or
  "string": "string" (non-shorthand)

If key_type is a static string value such as x, returns

  x=string (shorthand) or
  "x": "string" (non-shorthand).

If key_type or value_type are None, returns string representation of
key or value

Args:
  key_type: Callable[[str], Any] | str | None, type function for the key
  value_type: Callable[[str], Any] | None, type function for the value
  shorthand: bool, whether to display the example in shorthand

Returns:
  str, example of key-value pair
Nz{}=z: )rv   rH   )key_type
value_typer   key_str	value_strs        r   GetNestedKeyValueExampler}      sq    0 #87'$Z;)h8J//)i'0D'8gYa	{#EgEYb$$r   c           	      :   [        X5      n[        U[        5      (       a  UR                  (       a  SnOA[        U[        5      (       a*  UR                  (       d  UR	                  XS9=(       d    UnOUnU(       a  SR                  U [        [        USS95      $ g)a  Returns help text for flag with arg_type.

Generates help text based on schema such that the final output will
look something like...

  *Foo*
      Required, Foo help text

Args:
  field_name: str, attribute we are generating help text for
  arg_type: Callable[[str], Any] | None, type of the attribute we are getting
    help text for
  required: bool, whether the attribute is required

Returns:
  string help text for specific attribute
N)r   z*{}*{}{}rb   )rN   )ri   r6   r   r   r    rf   rL   rP   )r   r2   r   default_usageusages        r   GetNestedUsageHelpTextr     s    $ !6-,''HOOE(L))(//!!*!@ 	 

 E L.a"@  r   )r   )Fr/   )r&   
__future__r   r   r   r(   typingr   sixwith_metaclassABCMetaobjectr   r,   rH   rL   rP   rX   r^   rV   rW   rd   ri   rq   rv   r}   r   r   r   r   <module>r      s    G &  ' 
  
93%%ckk6: 9**L *Z	K D8$c $4 $E#t)4D $43,4"%J$r   