
    0                     d   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KJ
r
  SS	KJr  SS
KJr  SSKJr  SSKrSq " S S\R&                  5      rS$S jrS%S jrS&S jrS&S jrS&S jrS&S jrS&S jrS&S jrS&S jrS&S jrS rS r S r!S r"S r#S r$S r%S  r&S&S! jr'S" r(S$S# jr)g)'z/Flags and helpers for the builds command group.    )absolute_import)division)unicode_literals)cloudbuild_util)actions)arg_parsers)base)
completers)	arg_utils)
propertiesNc                   (   ^  \ rS rSrU 4S jrSrU =r$ )BuildsCompleter"   c                 4   > [         [        U ]
  " SSSS.UD6  g )Nzcloudbuild.projects.buildszbuilds list --uri)
collectionlist_command )superr   __init__)selfkwargs	__class__s     .lib/googlecloudsdk/command_lib/builds/flags.pyr   BuildsCompleter.__init__$   s'    	/4) /(     r   )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r   "   s     r   r   c                 (    U R                  SUUSS9  g)zAdds a flag to select a region of the Cloud Build Service.

Args:
  parser: The argparse parser to add the arg to.
  hidden: If true, retain help but do not display it.
  required: If true, the field must be set or will raise an exception.
z--regiona[  The region of the Cloud Build Service to use.
Must be set to a supported region name (e.g. `us-central1`).
If unset, `builds/region`, which is the default region to use when working with Cloud Build resources, is used. If builds/region is unset, region is set to `global`.
Note: Region must be specified in 2nd gen repo; `global` is not supported.hiddenrequiredhelpNadd_argumentparserr$   r%   s      r   AddRegionFlagr+   +   s%     	#	  
$r   c                 V    U(       a  US-   nOSnUS-  nU R                  S[        US9  g)zAdds a 'build' arg to the given parser.

Args:
  parser: The argparse parser to add the arg to.
  intro: Introductory sentence.
  zsThe ID of the build is printed at the end of the build submission process, or in the ID column when listing builds.build)	completerr&   N)r(   r   )r*   intro	help_texts      r   AddBuildArgr3   @   sB     II O P)  r   c                 (    U R                  SUSSS9  g)z$Add a flag to disable layer caching.z
--no-cache
store_truea  If set, disable layer caching when building with Kaniko.

This has the same effect as setting the builds/kaniko_cache_ttl property to 0 for this build.  This can be useful in cases where Dockerfile builds are non-deterministic and a non-deterministic result should not be cached.)r$   actionr&   Nr'   r*   r$   s     r   AddNoCacheFlagr8   S   s#    %	  	&r   c           	      N    U R                  SU[        R                  " SSS9SS9  g)zAdd a disk size flag.z--disk-size100GB1TB)lower_boundupper_boundz(Machine disk size (GB) to run the build.)r$   typer&   N)r(   r   
BinarySizer7   s     r   AddDiskSizeFlagr@   a   s.    !!g5I5	  7r   c                 &    U R                  SUSS9  g)z,Add a GCS directory flag to hold build logs.z--gcs-log-dira?  A directory in Google Cloud Storage to hold build logs. If this field is not set, ```gs://[PROJECT_NUMBER].cloudbuild-logs.googleusercontent.com/``` will be created and used or ```gs://[PROJECT_NUMBER]-[builds/region]-cloudbuild-logs``` is used when you set `--default-buckets-behavior` to `REGIONAL_USER_OWNED_BUCKET`.r$   r&   Nr'   r7   s     r   AddGcsLogDirFlagrC   j   s     +	  r   c                 &    U R                  SUSS9  g)z/Add a GCS directory flag for staging the build.z--gcs-source-staging-dira  A directory in Google Cloud Storage to copy the source used for staging the build. If the specified bucket does not exist, Cloud Build will create one. If you don't set this field, ```gs://[PROJECT_ID]_cloudbuild/source``` is used or ```gs://[PROJECT_ID]_[builds/region]_cloudbuild/source``` is used when you set `--default-buckets-behavior` to `REGIONAL_USER_OWNED_BUCKET` and `builds/region` is not `global`.rB   Nr'   r7   s     r   AddGcsSourceStagingDirFlagrE   {   s!     O	  r   c                 &    U R                  SUSS9  g)zAdd a ignore file flag.z--ignore-filezEOverride the `.gcloudignore` file and use the specified file instead.rB   Nr'   r7   s     r   AddIgnoreFileFlagrG      s       r   c                   ^ [         R                  " 5       (       a  / SQmO/ SQm[        R                  " S[        R
                  " 5       R                  R                  U4S jSUS9q[        R                  R                  U 5        g)zAdd a machine type flag.)E2_HIGHCPU_32E2_HIGHCPU_8	E2_MEDIUMN1_HIGHCPU_32N1_HIGHCPU_8)C3_HIGHCPU_44C3_HIGHCPU_8C3_STANDARD_4z--machine-typec                 6   > [         R                  " U 5      T;   $ Nsix	text_type)smachine_type_choicess    r   <lambda>$AddMachineTypeFlag.<locals>.<lambda>   s    s}}Q/3GGr   z#Machine type used to run the build.include_filterhelp_strr$   N)r   IsDefaultUniverser   ChoiceEnumMapperr   GetMessagesModuleBuildOptionsMachineTypeValueValuesEnum_machine_type_flag_map
choice_argAddToParser)r*   r$   rW   s     @r   AddMachineTypeFlagre      sm    !!## %55::<&,'A'AG4 ##//7r   c                 P    U R                  SUS[        R                  " 5       SS9  g)zAdd a substitutions flag.z--substitutionsz	KEY=VALUEa  Parameters to be substituted in the build specification.

For example (using some nonsensical substitution keys; all keys must begin with
an underscore):

    $ gcloud builds submit . --config config.yaml \
        --substitutions _FAVORITE_COLOR=blue,_NUM_CANDIES=10

This will result in a build where every occurrence of ```${_FAVORITE_COLOR}```
in certain fields is replaced by "blue", and similarly for ```${_NUM_CANDIES}```
and "10".

Only the following built-in variables can be specified with the
`--substitutions` flag: REPO_NAME, BRANCH_NAME, TAG_NAME, REVISION_ID,
COMMIT_SHA, SHORT_SHA.

For more details, see:
https://cloud.google.com/cloud-build/docs/api/build-requests#substitutions
)r$   metavarr>   r&   N)r(   r   ArgDictr7   s     r   AddSubstitutionsFlagri      s/       r   c                 J    U R                  S5      nUR                  SUSS9  U$ )zAdds a flag to send the build to a workerpool.

Args:
  parser: The argparse parser to add the arg to.
  hidden: If true, retain help but do not display it.

Returns:
  worker pool flag group
zWorker pool only flags.z--worker-poolzvSpecify a worker pool for the build to run in. Format: projects/{project}/locations/{region}/workerPools/{workerPool}.rB   )add_argument_groupr(   )r*   r$   worker_poolss      r   AddWorkerPoolFlagrm      s=     **+DE,H  I 
r   c                     U R                  SS[        R                  " [        R                  R
                  R                  5      S9  g)zAdd a timeout flag.z	--timeoutzMaximum time a build is run before it is failed as `TIMEOUT`. It is specified as a duration; for example, "2h15m5s" is two hours, fifteen minutes, and five seconds. If you don't specify a unit, seconds is assumed. For example, "10" is 10 seconds.r&   r6   N)r(   r   StorePropertyr   VALUESbuildstimeoutr*   s    r   AddTimeoutFlagru      s@    = "":#4#4#;#;#C#CD  Fr   c                 0    U R                  SS[        SS9  g)zAdd a polling interval flag.z--polling-interval   z?Amount of time in seconds to wait between polling build status.)defaultr>   r&   N)r(   intrt   s    r   AddPollingIntervalFlagrz      s"    L	  Nr   c                 B    [         R                  R                  U 5        g)zAdd an async flag.N)r	   
ASYNC_FLAGrd   rt   s    r   AddAsyncFlagr}      s    //f%r   c                 &    U R                  SSSS9  g)zAdd a flag to suppress logs.z--suppress-logsz*If set, build logs not streamed to stdout.r5   ro   Nr'   rt   s    r   AddSuppressLogsFlagr      s    7  r   c           	          U R                  5       nUR                  SSSS9  UR                  SSSS9  UR                  S	[        R                  " [        [        [        S
.S9SSS9  g)Add config flags.z--tagz-ta  The tag to use with a "docker build" image creation. Cloud Build will run a remote "docker build -t $TAG .", where $TAG is the tag provided by this flag. The tag must be in the *gcr.io* or *pkg.dev* namespace. Specify a tag if you want Cloud Build to build using a Dockerfile instead of a build config file. If you specify a tag in this command, your source must include a Dockerfile. For instructions on building using a Dockerfile see https://cloud.google.com/cloud-build/docs/quickstart-build.)r&   z--configzcloudbuild.yamlz=The YAML or JSON file to use as the build configuration file.)rx   r&   z--pack)imagebuilderenv)specappenda  Uses CNCF [buildpack](https://buildpacks.io/) to create the app image.  The app "image" key/value must be provided.  The app image name must be in the *gcr.io* or *pkg.dev* namespace. To specify your own builder image use the optional "builder" key/value argument. By default ```gcr.io/buildpacks/builder``` is used.   To pass environment variables to the builder use the optional "env" key/value argument where value is a list of key values using [escaping](https://cloud.google.com/sdk/gcloud/reference/topic/escaping) if necessary.)r>   r6   r&   N)add_mutually_exclusive_groupr(   r   rh   str)r*   build_configs     r   AddConfigFlagsr     s    446,
D  E J  L cc#$NO  r   c                 x    U R                  S[        R                  " SS9SSS9  U R                  S[        SSS9  g	)
r   z--memoryGB)default_unitTz'Machine memory required to run a build.)r>   r$   r&   z--vcpu-countz+Machine vCPU count required to run a build.N)r(   r   r?   float)rl   s    r   AddConfigFlagsAlphar   &  sM    !!t44	  6
 8	  :r   c                 ,    [         R                  U 5      $ )zReturn a machine type.)rb   GetEnumForChoice)machine_type_flags    r   GetMachineTyper   4  s    		0	01B	CCr   c                 J    [        5       R                  R                  U 5        g)z^Adds a default buckets behavior flag.

Args:
  parser: The argparse parser to add the arg to.
N)#GetDefaultBucketsBehaviorFlagMapperrc   rd   rt   s    r   AddDefaultBucketsBehaviorFlagr   9  s     &'22>>vFr   c                     [         R                  " S[        R                  " 5       R                  R
                  S SU S9$ )zGets a mapper for default buckets behavior flag enum value.

Args:
  hidden: If true, retain help but do not display it.

Returns:
  A mapper for default buckets behavior flag enum value.
z--default-buckets-behaviorc                 4    [         R                  " U 5      S:g  $ )NUNSPECIFIEDrS   )rV   s    r   rX   5GetDefaultBucketsBehaviorFlagMapper.<locals>.<lambda>P  s    s}}Q/=@r   zHow default buckets are setup.rZ   )r   r^   r   r_   r`   (DefaultLogsBucketBehaviorValueValuesEnum)r$   s    r   r   r   B  s:     
	#	#"

+
+
-==@/
 r   c                 4    [        5       R                  U 5      $ )zReturns default buckets behavior option.

Args:
  buckets_behavior_flag: The string value of default buckets behavior flag.

Returns:
  The enum of default buckets behavior flag.
)r   r   )buckets_behavior_flags    r   GetDefaultBuckestBehaviorr   V  s     
-	.	?	?
 r   c                 (    U R                  SUUSS9  g)zAdds a flag to define a service account to run the build with.

Args:
  parser: The argparse parser to add the arg to.
  hidden: If true, retain help but do not display it.
  required: If true, the field must be set or will raise an exception.
z--service-accountz`The service account to use with this build. 
If unset, the default service account will be used.r#   Nr'   r)   s      r   AddServiceAccountFlagr   d  s%     	<	  =r   )FFrR   )F)*__doc__
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.callioper   r   r	   googlecloudsdk.command_lib.utilr
   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   rT   rb   ListCommandCompleterr   r+   r3   r8   r@   rC   rE   rG   re   ri   rm   ru   rz   r}   r   r   r   r   r   r   r   r   r   r   r   <module>r      s     6 &  ' = + / ( 6 : * 
 j55 $*&&7""84:(FN&
"J:D
G(=r   