
                             S r SSKJr  SSKJr  SSKJr  SSKrSSKr " S S\R                  " \R                  \	5      5      r
 " S S	\	5      r " S
 S\	5      rg)aX  Abstract base class for concepts.

This base class cannot be used as a concept on its own but must be subclassed,
and the methods Attribute(), GetPresentationName(), and Parse() must be
implemented.

Example usage:

class IntConcept(Concept):

  def __init__(self, **kwargs):
    super(IntConcept, self).__init__(name='int', **kwargs)

  def Attribute(self):
    return Attribute(concept=self,
                     fallthroughs=self.fallthroughs,
                     help=self.BuildHelpText(),
                     required=self.required,
                     hidden=self.hidden,
                     completer=self.completer,
                     metavar=self.metavar)

  def GetPresentationName(self):
    return googlecloudsdk.command_lib.concepts.names.FlagNameFormat(
        self.name)

  def BuildHelpText(self):
    super(IntConcept, self).BuildHelpText() + ' Must be an int.'

  def Parse(self, dependencies):
    try:
      return int(dependencies.value)
    except ValueError:
      raise googlecloudsdk.command_lib.concepts.exceptions.Error(
          'Could not parse int concept; you provided [{}]'
          .format(dependencies.value))

* Note for Concept Implementers *
When implementing a new concept that produces a single argument, you can
subclass googlecloudsdk.command_lib.concepts.all_concepts.SimpleArg in order to
take advantage of general functionality, such as creating a simple presentation
name based on whether concept.positional is True, determining whether the
produced attribute is required, raising an exception if no value is found and
the concept is required, and storing fallthroughs.
    )absolute_import)division)unicode_literalsNc                       \ rS rSrSr  SS jr\R                  S 5       r\R                  S 5       r	S r
S r\R                  S	 5       r\R                  S
 5       rS rSrg)ConceptE   a	  Abstract base class for concept args.

Attributes:
  name: str, the name of the concept. Used to determine
    the argument or group name of the concept.
  key: str, the name by which the parsed concept is stored in the dependency
    view. If not given, is the same as the concept's name. Generally,
    this should only be set and used by containing concepts when parsing
    from a DependencyView object. End users of concepts do not need to
    use it.
  help_text: str, the help text to be displayed for this concept.
  required: bool, whether the concept must be provided by the end user. If
    False, it's acceptable to have an empty result; otherwise, an empty
    result will raise an error.
  hidden: bool, whether the associated argument or group should be hidden.
Nc                 h    Xl         X0l        X@l        XPl        U=(       d    U R                   U l        g N)name	help_textrequiredhiddenkey)selfr   r   r   r   r   s         /lib/googlecloudsdk/command_lib/concepts/base.py__init__Concept.__init__W   s&    INMKdiiDH    c                     [         e)zReturns an Attribute object representing the attributes.

Must be defined in subclasses.

Returns:
  Attribute | AttributeGroup, the attribute or group.
NotImplementedErrorr   s    r   	AttributeConcept.Attribute_   s
     r   c                     [         e)z&Returns the main name for the concept.r   r   s    r   GetPresentationNameConcept.GetPresentationNamej   s
     r   c                     U R                   $ )zRBuilds and returns the help text.

Returns:
  str, the help text for the concept.
)r   r   s    r   BuildHelpTextConcept.BuildHelpTexto   s     >>r   c                     g)z8Returns the list of concepts that this concept marshals.N r   s    r   MarshalConcept.Marshalw   s    r   c                     [         e)zParses the concept.

Args:
  dependencies: a DependenciesView object.

Returns:
  the parsed concept.

Raises:
  googlecloudsdk.command_lib.concepts.exceptions.Error, if parsing fails.
r   )r   dependenciess     r   ParseConcept.Parse{   s
     r   c                     g)zEReturns whether this concept is required to be specified by argparse.Fr"   r   s    r   IsArgRequiredConcept.IsArgRequired   s     r   c                 Z    U R                  5       U R                  5       U R                  S.$ )z9Returns argparse kwargs shared between all concept types.)helpr   r   )r   r*   r   r   s    r   MakeArgKwargsConcept.MakeArgKwargs   s-     ""$&&(++ r   )r   r   r   r   r   )N FF)__name__
__module____qualname____firstlineno____doc__r   abcabstractmethodr   r   r   r#   r'   r*   r.   __static_attributes__r"   r   r   r   r   E   s    " =B         r   r   c                   2    \ rS rSrSrSS jr\S 5       rSrg)r      a  An attribute that gets transformed to an argument.

Attributes:
  concept: Concept, the underlying concept.
  key: str, the name by which the Attribute is looked up in the dependency
    view.
  fallthroughs: [deps.Fallthrough], the list of fallthroughs for the concept.
  kwargs: {str: any}, other metadata describing the attribute. Available
    keys include: required (bool), hidden (bool), help (str), completer,
    default, nargs.  **Note: This is currently used essentially as a
    passthrough to the argparse library.
Nc                 <    Xl         U=(       d    / U l        X0l        g r
   conceptfallthroughskwargs)r   r=   r>   r?   s       r   r   Attribute.__init__   s    L$*DKr   c                 6    U R                   R                  5       $ )z7A string property representing the final argument name.)r=   r   r   s    r   arg_nameAttribute.arg_name   s     <<++--r   r<   NN)	r1   r2   r3   r4   r5   r   propertyrB   r8   r"   r   r   r   r      s     
 . .r   r   c                   "    \ rS rSrSrSS jrSrg)AttributeGroup   a?  Represents an object that gets transformed to an argument group.

Attributes:
  concept: Concept, the underlying concept.
  key: str, the name by which the Attribute is looked up in the dependency
    view.
  attributes: [Attribute | AttributeGroup], the list of attributes or
    attribute groups contained in this attribute group.
  kwargs: {str: any}, other metadata describing the attribute. Available
    keys include: required (bool), mutex (bool), hidden (bool), help (str).
    **Note: This is currently used essentially as a passthrough to the
    argparse library.
Nc                 ^    Xl         UR                  U l        U=(       d    / U l        X0l        g r
   )r=   r   
attributesr?   )r   r=   rJ   r?   s       r   r   AttributeGroup.__init__   s#    L{{DH &BDOKr   )rJ   r=   r   r?   rD   )r1   r2   r3   r4   r5   r   r8   r"   r   r   rG   rG      s    r   rG   )r5   
__future__r   r   r   r6   sixwith_metaclassABCMetaobjectr   r   rG   r"   r   r   <module>rQ      sT   ,\ '  ' 
 
Pc  f5 Pf. .2V r   