1# -*- coding: utf-8 -*- #
2# Copyright 2019 Google LLC. 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"""Flags for data-catalog commands."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import unicode_literals
20
21from googlecloudsdk.calliope import base
22from googlecloudsdk.calliope.concepts import concepts
23from googlecloudsdk.command_lib.util.apis import yaml_data
24from googlecloudsdk.command_lib.util.concepts import concept_parsers
25from googlecloudsdk.command_lib.util.concepts import presentation_specs
26
27
28def GetEntryArg():
29  entry_data = yaml_data.ResourceYAMLData.FromPath('data_catalog.entry')
30  resource_spec = concepts.ResourceSpec.FromYaml(entry_data.GetData())
31  presentation_spec = presentation_specs.ResourcePresentationSpec(
32      name='entry', concept_spec=resource_spec, group_help='Entry to update.')
33  return concept_parsers.ConceptParser([presentation_spec])
34
35
36def GetLookupEntryArg():
37  """Returns the argument for looking up an entry."""
38  help_text = """\
39The name of the target resource whose entry to update. This can be either the
40Google Cloud Platform resource name or the SQL name of a Google Cloud Platform
41resource. This flag allows one to update the entry corresponding to the lookup
42of the given resource, without needing to specify the entry directly."""
43  return base.Argument(
44      '--lookup-entry',
45      metavar='RESOURCE',
46      help=help_text)
47
48
49def AddEntryUpdateArgs():
50  # Normally these arguments would be added in a mutex group, but the help
51  # text would look confusing in this case since --lookup-entry shows up
52  # under positional arguments despite being a flag.
53  return [GetEntryArg(), GetLookupEntryArg()]
54