HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //snap/google-cloud-cli/394/lib/googlecloudsdk/command_lib/cloudlocationfinder/flags.py
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities for flags for `gcloud cloudlocationfinder` commands."""

import sys

from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.calliope.concepts import deps
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs


def LocationAttributeConfig():
  """Returns the attribute config for a Cloud location.

  Returns:
    concepts.ResourceParameterAttributeConfig: Attribute config for a Cloud
      location.
  """
  return concepts.ResourceParameterAttributeConfig(
      name='location',
      help_text='The Cloud location for the {resource}.',
      fallthroughs=[
          deps.Fallthrough(lambda: 'global', 'location is always global')
      ],
  )


def GetLocationResourceSpec():
  """Returns the resource spec for a Cloud location.

  Returns:
    concepts.ResourceSpec: Resource spec for a Cloud location.
  """
  return concepts.ResourceSpec(
      resource_collection='cloudlocationfinder.projects.locations',
      resource_name='location',
      locationsId=LocationAttributeConfig(),
      projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
  )


def SourceCloudLocationAttributeConfig():
  """Returns the attribute config for a source Cloud location.

  Returns:
    concepts.ResourceParameterAttributeConfig: Attribute config for a source
      Cloud location.
  """
  return concepts.ResourceParameterAttributeConfig(
      name='cloud_location', help_text='The source Cloud location.'
  )


def GetSourceCloudLocationResourceSpec():
  """Returns the resource spec for a source Cloud location.

  Returns:
    concepts.ResourceSpec: Resource spec for a source Cloud location.
  """
  return concepts.ResourceSpec(
      resource_collection=(
          'cloudlocationfinder.projects.locations.cloudLocations'
      ),
      resource_name='source_cloud_location',
      locationsId=LocationAttributeConfig(),
      projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
      cloudLocationsId=SourceCloudLocationAttributeConfig(),
  )


def AddLocationFlag(parser):
  """Adds a flag for specifying a location.

  Args:
    parser: The parser to add the flag to.
  """
  concept_parsers.ConceptParser.ForResource(
      name='--location',
      resource_spec=GetLocationResourceSpec(),
      group_help='The resource location.',
      required=False,
  ).AddToParser(parser)


def AddSourceCloudLocationFlag(parser, flag_name_overrides=None):
  """Adds a flag for specifying a source Cloud location.

  Args:
    parser: The parser to add the flag to.
    flag_name_overrides: A dictionary of flag name overrides.
  """
  concept_parsers.ConceptParser(
      [
          presentation_specs.ResourcePresentationSpec(
              name='--source-cloud-location',
              concept_spec=GetSourceCloudLocationResourceSpec(),
              group_help='The source Cloud location.',
              required=True,
              flag_name_overrides=flag_name_overrides,
          )
      ],
      command_level_fallthroughs={
          '--source-cloud-location.location': ['--location']
      },
  ).AddToParser(parser)


def AddListFlags(parser):
  """Adds flags for listing Cloudlocations to the given parser.

  Args:
    parser: The parser to add the flags to.
  """
  base.SORT_BY_FLAG.RemoveFromParser(parser)
  AddLocationFlag(parser)


def AddSearchFlags(parser):
  """Adds flags for searching Cloudlocations to the given parser.

  Args:
    parser: The parser to add the flags to.
  """
  AddLocationFlag(parser)
  AddSourceCloudLocationFlag(parser, flag_name_overrides={'location': ''})
  parser.add_argument(
      '--query',
      help='Query to use for searching Cloudlocations.',
  )
  parser.add_argument(
      '--limit',
      type=arg_parsers.BoundedInt(1, sys.maxsize, unlimited=True),
      help='Maximum number of resources to return.',
  )
  parser.add_argument(
      '--page-size',
      type=arg_parsers.BoundedInt(1, sys.maxsize, unlimited=True),
      help='Maximum number of resources per page.',
  )