
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ  G d	 d
e	j                        Zy)z+Parameter info lib for resource completers.    )absolute_import)division)unicode_literals)deps)util)parameter_info_lib)
propertiesc                   D     e Zd ZdZ fdZddZd ZddZ	 	 d	dZ xZ	S )
ResourceParameterInfoz+Gets parameter info for resource arguments.c                 >    || _         t        t        |   ||fi | y)zInitializes.N)resource_infosuperr   __init__)selfr   parsed_argsargumentkwargs	__class__s        Glib/googlecloudsdk/command_lib/util/concepts/resource_parameter_info.pyr   zResourceParameterInfo.__init__   s+    &D	
/     c                    ~| j                   j                  j                  |      }t        j                  j
                  j                  j                         }t        j                  j
                  j                  j                  d       	 |r:t        j                  || j                   j                         | j                        nd	 t        j                  j
                  j                  j                  |       S # t        j                  $ r6 Y t        j                  j
                  j                  j                  |       yw xY w# t        j                  j
                  j                  j                  |       w xY w)zReturns the program state value for parameter_name.

    Args:
      parameter_name: The parameter name.
      check_properties: bool, whether to check the properties (unused).

    Returns:
      The program state value for parameter_name.
    T)r   N)r   resource_specAttributeNamer	   VALUEScoredisable_promptsGetBoolSetr   GetBuildFullFallthroughsMapr   AttributeNotFoundError)r   parameter_namecheck_propertiesattribute_namecurrents        r   GetValuezResourceParameterInfo.GetValue&   s*    	((66~F $$44<<>G **..t4: ,: XX




5
5
7&&( @DD ,,009 && ,,009 ,,009s$   =C? ?EE EE 5F c                 L    | j                   j                  j                  |      S )zCHelper function to get the corresponding attribute for a parameter.)r   r   r   )r   r"   s     r   _AttributeNamez$ResourceParameterInfo._AttributeNameB   s    ++99.IIr   c                     ~| j                  |      }| j                  j                  j                  |d      }|syt	        j
                  |      S )a  Returns the argument parser dest name for parameter_name with prefix.

    Args:
      parameter_name: The resource parameter name.
      prefix: The prefix name for parameter_name if not None.

    Returns:
      The argument parser dest name for parameter_name.
    N)r(   r   attribute_to_args_mapgetr   NamespaceFormat)r   r"   prefixr$   	flag_names        r   GetDestzResourceParameterInfo.GetDestF   sP     	((8N""88<<^=ACI	**r   c                     ~| j                  |      }| j                  j                  j                  |d      }|s	|dk(  rd}ny| j	                  |      }||k7  r||}|r|du r|S dj                  ||      S y)aw  Returns the command line flag for parameter.

    If the flag is already present in program values, returns None.
    If the user needs to specify it, returns a string in the form
    '--flag-name=value'. If the flag is boolean and True, returns '--flag-name'.

    Args:
      parameter_name: The parameter name.
      parameter_value: The parameter value if not None. Otherwise
        GetValue() is used to get the value.
      check_properties: Check property values if parsed_args don't help.
      for_update: Return flag for a cache update command.

    Returns:
      The command line flag  for the parameter, or None.
    Nprojectz	--projectTz{name}={value})namevalue)r(   r   r*   r+   r&   format)r   r"   parameter_valuer#   
for_updater$   r.   program_values           r   GetFlagzResourceParameterInfo.GetFlagX   s    $ 	((8N""88<<I 
9	$	MM.1M-'		 '	d"
&&I_&MMr   )T)N)NTF)
__name__
__module____qualname____doc__r   r&   r(   r/   r8   __classcell__)r   s   @r   r   r      s(    3:8J+$ 5905&r   r   N)r<   
__future__r   r   r    googlecloudsdk.calliope.conceptsr   r   googlecloudsdk.command_lib.utilr   googlecloudsdk.corer	   ParameterInfoByConventionr    r   r   <module>rD      s4    2 &  ' 1 1 > *c.HH cr   