1# -*- coding: utf-8 -*- # 2# Copyright 2019 Google Inc. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15"""Common flags for some of the Service Directory commands.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import unicode_literals 20 21from googlecloudsdk.calliope import arg_parsers 22from googlecloudsdk.calliope import base 23 24 25def AddAddressFlag(parser): 26 """Adds an address flag for service-directory commands.""" 27 return base.Argument( 28 '--address', 29 help="""\ 30 IPv4 or IPv6 address of the endpoint. The default is 31 empty string.""").AddToParser(parser) 32 33 34def AddPortFlag(parser): 35 """Adds a port flag for service-directory commands.""" 36 return base.Argument( 37 '--port', 38 help="""\ 39 Port that the endpoint is running on, must be in the range of 40 [0, 65535]. The default is 0.""", 41 type=int).AddToParser(parser) 42 43 44def AddAnnotationsFlag(parser, resource_type, dictionary_size_limit): 45 """Adds annotations flags for service-directory commands.""" 46 return base.Argument( 47 '--annotations', 48 metavar='KEY=VALUE', 49 type=arg_parsers.ArgDict(), 50 help="""\ 51 Annotations for the {}. 52 53 Annotations take the form of key/value string pairs. Keys are 54 composed of an optional prefix and a name segment, separated by a 55 slash(/). Prefixes and names must be composed of alphanumeric 56 characters, dashes, and dots. Names may also use underscores. There 57 are no character restrictions on what may go into the value of an 58 annotation. The entire dictionary is limited to {} characters, spread 59 across all key-value pairs. 60 """.format(resource_type, dictionary_size_limit)).AddToParser(parser) 61 62 63def AddMetadataFlag(parser, resource_type, dictionary_size_limit): 64 """Adds metadata flags for service-directory commands.""" 65 return base.Argument( 66 '--metadata', 67 metavar='KEY=VALUE', 68 type=arg_parsers.ArgDict(), 69 help="""\ 70 Metadata for the {}. 71 72 Metadata takes the form of key/value string pairs. Keys are 73 composed of an optional prefix and a name segment, separated by a 74 slash(/). Prefixes and names must be composed of alphanumeric 75 characters, dashes, and dots. Names may also use underscores. There 76 are no character restrictions on what may go into the value of a 77 metadata. The entire dictionary is limited to {} characters, spread 78 across all key-value pairs. 79 """.format(resource_type, dictionary_size_limit)).AddToParser(parser) 80 81 82def AddLabelsFlag(parser, resource_type): 83 """Adds labels flags for service-directory commands.""" 84 return base.Argument( 85 '--labels', 86 metavar='KEY=VALUE', 87 type=arg_parsers.ArgDict(), 88 help="""\ 89 Resource labels associated with the {}. 90 """.format(resource_type)).AddToParser(parser) 91 92 93def AddMaxEndpointsFlag(parser): 94 """Adds max_endpoints flags for service-directory commands.""" 95 return base.Argument( 96 '--max-endpoints', 97 type=int, 98 help="""\ 99 Maximum number of endpoints to return. 100 """).AddToParser(parser) 101 102 103def AddEndpointFilterFlag(parser): 104 """Adds endpoint filter flags for service-directory commands.""" 105 return base.Argument( 106 '--endpoint-filter', 107 help="""\ 108 Apply a Boolean filter EXPRESSION to each endpoint in the service. 109 If the expression evaluates True, then that endpoint is listed. 110 """).AddToParser(parser) 111