
                         :   S r SSKrSSKJr  SSKJr  SSKJr  SSS.r	S	\R                  S
\\   S\\   4S jr\R                  \R                  \R                   " \R"                  R$                  5       " S S\R&                  5      5       5       5       r\	\l        g)z''logging saved_queries update' command.    N)util)base)logging_v2_messagesz"        Update a saved query.
    z        To update the display name and description of a saved query, run:

          $ {command} my-saved-query --display-name="New Name" --description="New Description"
    )DESCRIPTIONEXAMPLESargscurrent_summary_fieldsreturnc                 4   U R                   (       a  / nO[        U5      nU R                  (       a+  U R                   H  nX2;  d  M
  UR                  U5        M     U R                  (       a+  U R                   H  nX2;   d  M
  UR                  U5        M     U$ )zCalculates the new list of summary fields based on user arguments.

Args:
  args: An argparse namespace with command-line arguments.
  current_summary_fields: The current list of summary fields.

Returns:
  A list of updated summary fields.
)clear_summary_fieldslistadd_summary_fieldappendremove_summary_fieldremove)r   r	   new_summary_fieldsfields       +lib/surface/logging/saved_queries/update.py_get_updated_summary_fieldsr   (   s     
45	''		(!!%( ( 
**		$!!%( + 
    c                       \ rS rSrSr\S\R                  SS4S j5       rS\R                  S\
R                  4S jrS	rg)
UpdateD   zNUpdate Logging saved queries.

Updates a saved query in Google Cloud Logging.
parserr
   Nc                 X   U R                  SSS9  [        R                  " U S5        [        R                  " U SS5        U R                  SSS9  U R                  S	S
S9  U R                  SSS9  U R                  SSS9  U R	                  SS9nUR                  SSS9  UR	                  5       nUR                  SSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR	                  SS9nUR                  S[
        SS 9  UR                  S![
        S"S 9  g#)$zRegisters flags for this command.

Args:
  parser: An argparse.ArgumentParser object. The parser that will be used to
    parse the command line arguments.
SAVED_QUERY_IDz ID of the saved query to update.)helpzsaved query to updateFzLocation of the saved query.z--namez%The resource name of the saved query.z--display-namez$The display name of the saved query.z--descriptionz#The description of the saved query.z--visibilityz"The visibility of the saved query.T)mutexz--sql-query-textzThe SQL query text. If this argument is specified, no LoggingQuery arguments (--filter, --add-summary-field, etc.) may be specified.z--filterzYThe logging filter. If this argument is specified, --sql-query-text may not be specified.z--add-summary-fieldr   zAdd a summary field.)actionr   z--remove-summary-fieldzRemove a summary field.z--clear-summary-fields
store_truezClear all summary fields.z--summary-field-startzSummary field start.)typer   z--summary-field-endzSummary field end.N)add_argumentr   AddParentArgsAddBucketLocationArg	add_groupint)r   query_group	ops_groupsummary_ranges       r   ArgsUpdate.ArgsM   s    A   	v67fe-KL
'NO
E   C   A   """.K    %%'I5   h5K    &  
  (   ''d'3Mc0F   C.B  r   r   c           
         [         R                  " 5       nUR                  =(       d    Sn[         R                  " [         R                  " [         R                  " U5      SU5      SUR
                  5      n0 n/ nUR                  S5      (       a   UR                  US'   UR                  S5        UR                  S5      (       a   UR                  US'   UR                  S5        UR                  S5      (       a   UR                  US'   UR                  S5        UR                  S5      (       aK  [        R                  R                  UR                  R                  5       5      US'   UR                  S5        UR                  S	5      (       a4  [        R                   " UR"                  S
9US'   UR                  S5        GO0 nUR                  S5      (       a   UR$                  US'   UR                  S5        UR                  S5      (       a   UR&                  US'   UR                  S5        UR                  S5      (       a   UR(                  US'   UR                  S5        [+        UR                  S5      UR                  S5      UR                  S5      /5      (       a  UR,                  R/                  [        R0                  " US95      n/ n	UR2                  (       aK  UR2                  R4                  (       a0  UR2                  R4                   V
s/ s H  n
U
R6                  PM     n	n
[9        X5      nU V
s/ s H  n
[        R:                  " U
S9PM     sn
US'   UR                  S5        U(       a  [        R<                  " S0 UD6US'   UR,                  R?                  [        R@                  " U[        R                  " S0 UD6SRC                  U5      S95      $ s  sn
f s  sn
f ) zUpdates a saved query using the Logging API.

Args:
  args: An argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  The updated SavedQuery.
global	locationssavedQueriesnamedisplay_namedisplayNamedescription
visibilitysql_query_text)sqlQueryTextopsAnalyticsQueryzopsAnalyticsQuery.sqlQueryTextfilterzloggingQuery.filtersummary_field_startsummaryFieldStartzloggingQuery.summaryFieldStartsummary_field_endsummaryFieldEndzloggingQuery.summaryFieldEndr   r   r   )r0   )r   summaryFieldszloggingQuery.summaryFieldsloggingQuery,)r0   
savedQuery
updateMask )"r   	GetClientlocationCreateResourceNameGetParentFromArgsr   IsSpecifiedr0   r   r1   r3   messages
SavedQueryVisibilityValueValuesEnumr4   upperOpsAnalyticsQueryr5   r8   r9   r;   anyprojects_locations_savedQueriesGet.LoggingProjectsLocationsSavedQueriesGetRequestr>   r=   r   r   SummaryFieldLoggingQueryPatch0LoggingProjectsLocationsSavedQueriesPatchRequestjoin)selfr   clientrD   resource_namesaved_query_dataupdate_masklogging_query_datacurrent_saved_queryr	   r   r   s               r   Run
Update.Run   s    ^^F}}(H++""4(+x	
 	M K!%v ''(,(9(9}%'&&(,(8(8}%'%%



7
78M8M8O
P |$ &
 ()).6.H.H**/*+ 9:			(	#	#'+{{8$01			/	0	0262J2J./;<			-	.	.040F0F,-9:	


.
/


1
2


1
2 
	 
	
 %DDHHCC"

 "$,,#00>> /;;II$I% kkI ! $
 9

 =O/
<N5H!!.<N/
?+ 	78	+3+@+@ ,
 ,
( 1177AA**>-=>xx,	
 '$/
s   O-O2rB   )__name__
__module____qualname____firstlineno____doc__staticmethodargparseArgumentParserr*   	NamespacerH   rI   r]   __static_attributes__rB   r   r   r   r   D   sR    
 ?8** ?t ? ?Bah(( aX-@-@ ar   r   )rc   re   googlecloudsdk.api_lib.loggingr   googlecloudsdk.callioper   0googlecloudsdk.generated_clients.apis.logging.v2r   rH   DETAILED_HELPrg   r   strr   HiddenDefaultUniverseOnlyReleaseTracksReleaseTrackGACommandr   detailed_helprB   r   r   <module>ru      s     .  / ( \	
	 


6:3i	#Y8 D%%(()iT\\ i *  iX % r   