
                             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	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g)z"The configs variables set command.    )absolute_import)division)unicode_literalsN)
exceptions)util)base)flags)log)http_encodingc                   B    \ rS rSrSrSS0r\S 5       rS rS r	S r
S	rg
)Set!   zCreate or update variable resources.

This command creates or updates a variable resource, setting its value to
the specified string or file contents.
EXAMPLESaS            To create or update a variable named "my-var", run:

            $ {command} --config-name=my-config my-var "my value"

          To create or update a variable with a hierarchical name, such as
          "results/task1", run:

            $ {command} --config-name=my-config results/task1 "my value"

          To create a variable, but fail if it already exists, run:

            $ {command} --config-name=my-config my-var "my-value" --fail-if-present

          To update a variable, but fail if it does not exist, run:

            $ {command} --config-name=my-config my-var "my-value" --fail-if-absent

          It is possible to provide --is-text flag if the value contains only
          text (UTF-8 encoded). This affects how the variable is transmitted on
          the wire and requires less quota on the backend.

            $ {command} --config-name=my-config --is-text my-var "my value"

          If the variable's value parameter is not specified, the value will be
          read from standard input. This allows setting variables to large values
          or values that contain non-printable characters. The variable value
          will be automatically base64-encoded. For example, to set a variable's
          value to the contents of a file, run:

            $ cat my-file | {command} --config-name my-config my-var
          c                     [         R                  " U 5        U R                  5       nUR                  SSSS9  UR                  SSSS9  U R                  SSS	9  U R                  S
SSSS9  U R                  SSSSSS9  g)zArgs is called by calliope to gather arguments for this command.

Args:
  parser: An argparse parser that you can use to add arguments that go
      on the command line after this command. Positional arguments are
      allowed.
z--fail-if-presentz:Fail if a variable with the specified name already exists.
store_true)helpactionz--fail-if-absentz:Fail if a variable with the specified name does not exist.namezThe variable name.)r   value?NzThe variable value. If absent, the value will be read from stdin. The value is automatically base64-encoded, unless --is-text flag is set.)nargsdefaultr   z	--is-textFzIf True, send and store the value as text. Can be used if the value contains only text (UTF-8 encoded). This affects how the variable is transmitted on the wire and requires less quota on the backend.)r   requiredr   r   )r	   AddRequiredConfigFlagadd_mutually_exclusive_groupadd_argument)parser
fail_groups     3lib/surface/runtime_config/configs/variables/set.pyArgsSet.ArgsK   s     
'446JI   I  
 %9:
,  .  %!&+6	  8    c                    [         R                  " UR                  U5      nUR                  c>  [        R
                  R                  S5        [        R                  R                  5       nOUR                  nUR                  (       a  U R                  XU5      $  U R                  XU5      $ ! [        R                   a'    UR                  (       d  U R                  XU5      s $ e f = f)zRun 'runtime-configs variables set'.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
      with.

Returns:
  The new variable.

Raises:
  HttpException: An http error response was received while executing api
      request.
z6No value argument specified; reading value from stdin.)r   ParseVariableNamer   r   r
   statusPrintsysstdinreadfail_if_absent_Update_Createapitools_exceptionsHttpConflictErrorfail_if_present)selfargsvar_resourcer   s       r   RunSet.Runt   s     ))$))T:Lzz	jjOPiinnejje\\$e44	||D66 22  ##d%8
8 	s   B/ /7C*(C*c                    [         R                  " 5       n[         R                  " 5       nUR                  nUR                  nUR                  UR                  [         R                  " Xg5      UR                  UR                  5       UR                  (       d  [        R                  " U5      OS UR                  (       a  UOS S9S95      n[        R                  " U5        [         R                  " U5      $ )Nr   r   text)parentvariable)r   VariableClientMessages
projectsId	configsIdCreate2RuntimeconfigProjectsConfigsVariablesCreateRequest
ConfigPathVariableRelativeNameis_textr   Encoder
   CreatedResourceFormatVariable)	r0   r1   r2   r   variable_clientmessagesprojectconfigresults	            r   r,   Set._Create   s    ))+O}}H%%G##F##CC??73&&!..09=m**514"llU '  	D 	
	F %v&&r"   c                 ~   [         R                  " 5       n[         R                  " 5       nUR                  UR	                  UR                  5       UR                  (       d  [        R                  " U5      OS UR                  (       a  UOS S95      n[        R                  " U5        [         R                  " U5      $ )Nr6   )r   r:   r;   UpdaterA   rB   rC   r   rD   r
   UpdatedResourcerF   )r0   r1   r2   r   rG   rH   rK   s          r   r+   Set._Update   s    ))+O}}H##**,59\\-&&u-t,,D 	 	
F %v&&r"    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr    r3   r,   r+   __static_attributes__rQ   r"   r   r   r   !   s>      !-F &8 &8P#J'*'r"   r   )rV   
__future__r   r   r   r'   apitools.base.pyr   r-   %googlecloudsdk.api_lib.runtime_configr   googlecloudsdk.callioper   )googlecloudsdk.command_lib.runtime_configr	   googlecloudsdk.corer
   googlecloudsdk.core.utilr   CreateCommandr   rQ   r"   r   <module>rb      s<     ) &  ' 
 > 6 ( ; # 2Z'$

 Z'r"   