
    g                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	   " S S	\	R                  5      rSS
 jrS rS rS rS rg)z?Utilities for handling YAML schemas for gcloud update commands.    )absolute_import)division)unicode_literals)	arg_utils)yaml_arg_schema)
exceptionsc                       \ rS rSrSrSrg)NoFieldsSpecifiedError   z7Raises when no arguments specified for update commands. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       2lib/googlecloudsdk/command_lib/util/apis/update.pyr
   r
      s    ?r   r
   c           	         U R                  5       (       d  [        S5      e[        5       n[        UR                  R
                  5       H  nUR                  [        XPX#5      5        M      SR                  [        U5      5      $ )a  Gets the fieldMask that is required for update api calls.

Args:
  args: The argparse parser.
  spec: The CommandData class.
  mask_path: string, the dotted path of mask in the api method
  is_dotted: Boolean, True if the dotted path of the name is returned.

Returns:
  A String, represents a mask specifying which fields in the resource should
  be updated.

Raises:
  NoFieldsSpecifiedError: this error would happen when no args are specified.
z4Must specify at least one valid parameter to update.,)
GetSpecifiedArgsr
   set_GetSpecParams	argumentsparamsupdate_GetMaskFieldsjoinsorted)argsspec	mask_path	is_dotted	field_setparams         r   GetMaskStringr&      sr      
			 	 
 >@ @ e)dnn334e^EFG 5 
&#	$$r   c                     [        5       nU R                  U5      (       d  U$ U R                   H)  n[        X%U5      nU(       d  M  UR	                  U5        M+     U$ )a  Gets the fieldMask based on the yaml arg and the arguments specified.

Args:
  param: yaml_arg_schema.YAMLArgument, the yaml argument added to parser
  args: parser_extensions.Namespace, user specified arguments
  mask_path: str, path to where update mask applies
  is_dotted: bool, True if the dotted path of the name is returned

Returns:
  Set of fields (str) to add to the update mask
)r   IsApiFieldSpecified
api_fields_ExtractMaskFieldadd)r%   r    r"   r#   r$   	api_field
mask_fields          r   r   r   :   sW     e)		"	"4	(	(##i"9CJzmmJ $ 
r   c              #      #    U  HH  n[        U[        R                  5      (       a"  [        UR                  5       H  nUv   M	     MD  Uv   MJ     g7f)zRecursively yields all the params in the spec.

Args:
  params: List of Argument or ArgumentGroup objects.

Yields:
  All the Argument objects in the command spec.
N)
isinstancer   ArgumentGroupr   r   )r   r%   ps      r   r   r   Q   sC      e%6677eoo.! / k s   AAc                     [        U R                  S5      5      nUR                  S5      nU(       a/  SU;   a  UR                  S5      nUSU nSR                  XCS 5      $ XC   $ )a  Extracts the api field name which constructs the mask used for request.

For most update requests, you have to specify which fields in the resource
should be updated. This information is stored as updateMask or fieldMask.
Because resource and mask are in the same path level in a request, this
function uses the mask_path as the guideline to extract the fields need to be
parsed in the mask.

Args:
  mask_path: string, the dotted path of mask in an api method, e.g. updateMask
    or updateRequest.fieldMask. The mask and the resource would always be in
    the same level in a request.
  api_field: string, the api field name in the resource to be updated and it
    is specified in the YAML files, e.g. displayName or
    updateRequest.instance.displayName.
  is_dotted: Boolean, True if the dotted path of the name is returned.

Returns:
  String, the field name of the resource to be updated..

.additionalPropertiesN)lensplitindexr   )r"   r,   r#   levelapi_field_listrepeated_indexs         r   r*   r*   b   sj    , iooc"
#%??3'./%++,BCn%o~6n88N6*++  r   c                 d   SnU R                  5       " 5       nU H  n[        X#5      (       d  M  Us  $    U R                  (       ak  U R                  nSn[        X$5      (       a!  [        R                  " UU5      R
                  nU H&  n[        XS5      (       d  M  SR                  XC5      s  $    g)zGets the dotted path of mask in the api method.

Args:
  method: APIMethod, The method specification.

Returns:
  String or None.
)
updateMask	fieldMaskNz{}.{})GetRequestTypehasattrrequest_fieldr   GetFieldFromMessagetypeformat)methodpossible_mask_fieldsmessagemaskr@   request_messages         r   GetMaskFieldPathrI      s     5!!#%' #dwk # ((MOw&&!55g6CEEIT  %		'	'~~m22 % 
r   N)T)r   
__future__r   r   r   $googlecloudsdk.command_lib.util.apisr   r   googlecloudsdk.corer   Errorr
   r&   r   r   r*   rI   r   r   r   <module>rN      sK    F &  ' : @ *@Z-- @%8."!Dr   