o
    €Ï³  ã                   @   s  d Z ddlmZ ddlmZ ddlmZ ddlZddlZG dd„ dejƒZG dd	„ d	eƒZG d
d„ deƒZ	G dd„ deƒZ
G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS ) z…Calliope parsing errors for logging and collecting metrics.

Refer to the calliope.parser_extensions module for a detailed overview.
é    )Úabsolute_import)Údivision)Úunicode_literalsNc                       s.   e Zd ZdZ		d‡ fdd„	Zdd„ Z‡  ZS )ÚArgumentErrora
  Base class for argument errors with metrics.

  ArgumentError instances are intercepted by
  parser_extensions.ArgumentParser.error(), which
    1. reports a failed command to metrics
    2. prints a usage diagnostic to the standard error
    3. exits with status 2, bypassing gcloud_main exception handling

  Attributes:
    argument: str, The argument name(s) causing the error.
    error_extra_info: {str: str}, Extra info dict for error_format.
    error_format: str, A .format() string for constructng the error message
      from error_extra_info.
    extra_path_arg: str, Dotted command path to append to the command path.
    parser: ArgmentParser, Used to generate the usage string for the command.
      This could be a different subparser than the command parser.
  Nc                    s:   || _ || _|| _|| _|| _tt| ƒ d t 	| ¡¡ d S )N)
Úerror_formatÚargumentÚextra_path_argÚparserÚerror_extra_infoÚsuperr   Ú__init__ÚsixÚ	text_type)Úselfr   r   r   r	   Úkwargs©Ú	__class__© úB/tmp/google-cloud-sdk/lib/googlecloudsdk/calliope/parser_errors.pyr   0   s   zArgumentError.__init__c              
   C   sž   t di | j¤Ž}	 z| jjdi |¤Ž}W n- ty3 } z|jd }d| d ||< W Y d }~nd }~w ttfy@   | j}Y nw q	| jrMdj| j|d}|S )NTr   Ú{Ú}zargument {argument}: {message})r   Úmessager   )	Údictr
   r   ÚformatÚKeyErrorÚargsÚ
IndexErrorÚ
ValueErrorr   )r   Úkeysr   ÚeÚkeyr   r   r   Ú__str__9   s&   
€ýøÿzArgumentError.__str__)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   Ú__classcell__r   r   r   r   r      s    ÿ	r   c                   @   ó   e Zd ZdZdS )ÚOtherParsingErrorz6Some other parsing error that is not any of the above.N©r"   r#   r$   r%   r   r   r   r   r(   M   ó    r(   c                   @   r'   )ÚTooFewArgumentsErrorz/Argparse didn't use all the Positional objects.Nr)   r   r   r   r   r+   Q   r*   r+   c                   @   r'   )ÚUnknownCommandErrorzUnknown command error.Nr)   r   r   r   r   r,   U   r*   r,   c                   @   r'   )ÚUnrecognizedArgumentsErrorz<User entered arguments that were not recognized by argparse.Nr)   r   r   r   r   r-   Y   r*   r-   c                   @   r'   )ÚDetailedArgumentErrorz:A DetailedArgumentError is preferable to an ArgumentError.Nr)   r   r   r   r   r.   ]   r*   r.   c                       ó    e Zd ZdZ‡ fdd„Z‡  ZS )ÚModalGroupErrorzModal group conflict error.c                    ó    t t| ƒj	dd|i|¤Ž d S )Nú{conflict} must be specified.Úconflict)r2   )r   r0   r   ©r   r3   r   r   r   r   r   d   ó   
ÿþ
ýzModalGroupError.__init__©r"   r#   r$   r%   r   r&   r   r   r   r   r0   a   ó    r0   c                       r/   )ÚOptionalMutexErrorzOptional mutex conflict error.c                    r1   )Nú+At most one of {conflict} can be specified.r3   )r9   )r   r8   r   r4   r   r   r   r   n   r5   zOptionalMutexError.__init__r6   r   r   r   r   r8   k   r7   r8   c                       r/   )ÚRequiredErrorzRequired error.c                    s   t t| ƒj	di |¤Ž d S )NúMust be specified.)r;   )r   r:   r   )r   r   r   r   r   r   x   s
   
ÿ
þzRequiredError.__init__r6   r   r   r   r   r:   u   r7   r:   c                       r/   )ÚRequiredMutexErrorzRequired mutex conflict error.c                    r1   )Nú,Exactly one of {conflict} must be specified.r3   )r=   )r   r<   r   r4   r   r   r   r      r5   zRequiredMutexError.__init__r6   r   r   r   r   r<   ~   r7   r<   c                   @   r'   )ÚWrongTrackErrorz)For parsed commands in a different track.Nr)   r   r   r   r   r>   ˆ   r*   r>   c                   @   r'   )ÚArgumentExceptionz>ArgumentException is for problems with the declared arguments.Nr)   r   r   r   r   r?   Œ   r*   r?   c                   @   r'   )ÚUnknownDestinationExceptionz<Fatal error for an internal dest that has no associated arg.Nr)   r   r   r   r   r@      r*   r@   )r%   Ú
__future__r   r   r   Úargparser   r   r(   r+   r,   r-   r.   r0   r8   r:   r<   r>   Ú	Exceptionr?   r@   r   r   r   r   Ú<module>   s&   0

	
