a
    còf  ã                   @   sR   d Z ddlZddlZddlmZ ddlZddlmZ dd„ Zdd„ Z	dd	d
„Z
dS )ae  Module that contains the command line app.

Why does this file exist, and why not put this in __main__?
  You might be tempted to import things from __main__ later, but that will
  cause problems: the code will get executed twice:
  - When you run `python -m sqlparse` python will execute
    ``__main__.py`` as a script. That means there won't be any
    ``sqlparse.__main__`` in ``sys.modules``.
  - When you import __main__ it will get executed again (as a module) because
    there's no ``sqlparse.__main__`` in ``sys.modules``.
  Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
é    N)ÚTextIOWrapper)ÚSQLParseErrorc                  C   s¤  g d¢} t jdddd�}| d¡ |jddd	d
dd� |jddtjd� | d¡}|jdddd| d d dd„ | D ƒ¡¡d� |jdddd| d d dd„ | D ƒ¡¡d� |jdd d!d"d#d$gd%d� |jd&d'd(d)d*d+� |jd,d-d.d(d)d/d+� |jd0d1d2td3d4� |jd5d6d(d)d7d+� |jd8d9d(d)d:d+� |jd;d<d(d)d=d>� |jd?d@d(d)dAd>� |jdBdCdDtdEd4� |jdFdGd)t	dHd4� |jdIdJd)t	dKd4� |jdLdMdNdOdP� |S )QN)ÚupperÚlowerÚ
capitalizeZ	sqlformatzEFormat FILE according to OPTIONS. Use "-" as FILE to read from stdin.z%(prog)s  [OPTIONS] FILE, ...)ÚprogÚdescriptionÚusageÚfilenamez-oz	--outfileÚoutfileÚFILEz)write output to FILE (defaults to stdout))ÚdestÚmetavarÚhelpz	--versionÚversion)Úactionr   zFormatting Optionsz-kz
--keywordsZCHOICEZkeyword_casez,change case of keywords, CHOICE is one of {}z, c                 s   s   | ]}d   |¡V  qdS ©z"{}"N©Úformat©Ú.0Úx© r   úI/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/sqlparse/cli.pyÚ	<genexpr>?   ó    z create_parser.<locals>.<genexpr>)r   r   Úchoicesr   z-iz--identifiersZidentifier_casez/change case of identifiers, CHOICE is one of {}c                 s   s   | ]}d   |¡V  qdS r   r   r   r   r   r   r   G   r   z-lz
--languageÚLANGZoutput_formatÚpythonÚphpzJoutput a snippet in programming language LANG, choices are "python", "php"z--strip-commentsÚstrip_commentsÚ
store_trueFzremove comments)r   r   Údefaultr   z-rz
--reindentZreindentzreindent statementsz--indent_widthZindent_widthé   z(indentation width (defaults to 2 spaces))r   r"   Útyper   z--indent_after_firstZindent_after_firstz2indent after first line of statement (e.g. SELECT)z--indent_columnsZindent_columnsz<indent all columns by indent_width instead of keyword lengthz-az--reindent_alignedz%reindent statements to aligned format)r   r"   r   z-sz--use_space_around_operatorsz*place spaces around mathematical operatorsz--wrap_afterZ
wrap_afterr   z*Column after which lists should be wrappedz--comma_firstZcomma_firstz-Insert linebreak before comma (default False)z	--compactÚcompactz2Try to produce more compact output (default False)z
--encodingÚencodingzutf-8z*Specify the input encoding (default utf-8))r   r"   r   )
ÚargparseÚArgumentParserÚadd_argumentÚsqlparseÚ__version__Úadd_argument_groupr   ÚjoinÚintÚbool)Z_CASE_CHOICESÚparserÚgroupr   r   r   Úcreate_parser    sî    ü
üý
ÿûÿûûûûûûûüüûûûür2   c                 C   s   t j d | ¡¡ dS )z5Print msg and optionally exit with return code exit_.z[ERROR] {}
é   )ÚsysÚstderrÚwriter   )Úmsgr   r   r   Ú_errorž   s    r8   c           
   
   C   s´  t ƒ }| | ¡} | jdkrNttjj| jd�}z| ¡ }W | 	¡  qÈ| 	¡  0 nzzBt
| j| jd��}d | ¡ ¡}W d   ƒ n1 s„0    Y  W n6 tyÆ } ztd | j|¡ƒW  Y d }~S d }~0 0 d}| j�r*zt
| jd| jd�}d}W n8 t�y& } ztd | j|¡ƒW  Y d }~S d }~0 0 ntj}t| ƒ}ztj |¡}W n4 t�y| } ztd	 |¡ƒW  Y d }~S d }~0 0 tj|fi |¤Ž}	| |	¡ | ¡  |�r°| ¡  d
S )Nú-)r&   Ú zFailed to read {}: {}FÚwTzFailed to open {}: {}zInvalid options: {}r   )r2   Ú
parse_argsr
   r   r4   ÚstdinÚbufferr&   ÚreadÚdetachÚopenr-   Ú	readlinesÚOSErrorr8   r   r   ÚstdoutÚvarsr*   Ú	formatterZvalidate_optionsr   r6   ÚflushÚclose)
Úargsr0   ÚwrapperÚdataÚfÚeZclose_streamÚstreamZformatter_optsÚsr   r   r   Úmain¤   sB    


0ÿ*$
rP   )N)Ú__doc__r'   r4   Úior   r*   Zsqlparse.exceptionsr   r2   r8   rP   r   r   r   r   Ú<module>	   s   ~