
    =                     F    d Z ddlZddlmZ  G d dej                        Zy)zProvides an ArgType for --preset flags.

This is a custom ArgType for the --preset flag that allows users to specify a
preset name with a dictionary of parameters for that preset.

Example:
  --preset my-preset:key1=value1,key2=value2
    N)arg_parsersc                   D     e Zd ZdZd fd	Z fdZed        Zd Z xZ	S )	PresetArgzInterpret argument as a named dict.

  The string before the colon is the preset name and the string after is a
  dictionary of parameters for the preset.

    --preset my-preset:key1=value1,key2=value2
  c                     t         |   |||       d}t        j                  |t        j                        | _        y )N)key_type
value_typecleanup_inputz([^:]+)(:?)(.*))super__init__recompileDOTALLpreset_arg_matcher)selfr   r   r	   preset_param_pattern	__class__s        0lib/googlecloudsdk/command_lib/run/preset_arg.pyr   zPresetArg.__init__&   s<    	Gj   - jj)=ryyID    c                     | j                   j                  |      }|s$t        j                  dj	                  |            |j                  d      }t        |   |j                  d            }||dS )Nz]Invalid preset value [{0}], expected format is <preset_name>:<key1>=<value1>,<key2>=<value2>.      )nameparams)r   matchr   ArgumentTypeErrorformatgroupr
   __call__)r   	arg_valuer   preset_nameparams_dictr   s        r   r   zPresetArg.__call__-   so    ##)))4E))<<BF9<M  ++a.K'"5;;q>2K;77r   c                      y)NF )r   s    r   hiddenzPresetArg.hidden8   s    r   c                     ~|S )Nr#   )r   is_custom_metavarmetavars      r   GetUsageMetavarzPresetArg.GetUsageMetavar<   s
    Nr   )NNT)
__name__
__module____qualname____doc__r   r   propertyr$   r(   __classcell__)r   s   @r   r   r      s,    J	8  r   r   )r,   r   googlecloudsdk.callioper   ArgDictr   r#   r   r   <module>r1      s$    
 /!## !r   