
    ,i                     R    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 Zd Z	d Z
d	dZy)
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                  J   g d} t        j                  ddd      }|j                  ddd	       |j                  d
dddd       |j                  ddddd       |j                  ddt        j                         |j                  d      }|j                  dddd| dj                  dj                  d  | D                    !       |j                  d"d#dd$| d%j                  dj                  d& | D                    !       |j                  d'd(d)d*d+d,gd-!       |j                  d.d/ddd0       |j                  d1d2d3ddd4       |j                  d5d6d7t        d89       |j                  d:d;ddd<       |j                  d=d>ddd?       |j                  d@dAdddBC       |j                  dDdEdddFC       |j                  dGdHdIt        dJ9       |j                  dKdLdt        dM9       |j                  dNdOdt        dP9       |j                  dQdRdSdTU       |S )VN)upperlower
capitalize	sqlformatzEFormat FILE according to OPTIONS. Use "-" as FILE to read from stdin.z"%(prog)s [OPTIONS] FILE [FILE ...])progdescriptionusagefilename+z%file(s) to format (use "-" for stdin))nargshelpz-oz	--outfileoutfileFILEz)write output to FILE (defaults to stdout))destmetavarr   z
--in-placeinplace
store_trueFz0format files in-place (overwrite existing files))r   actiondefaultr   z	--versionversion)r   r   zFormatting Optionsz-kz
--keywordsCHOICEkeyword_casez,change case of keywords, CHOICE is one of {}z, c              3   (   K   | ]
  }d | d   yw"N .0xs     @/var/www/mymood/env/lib/python3.12/site-packages/sqlparse/cli.py	<genexpr>z create_parser.<locals>.<genexpr>G        61!Ah   )r   r   choicesr   z-iz--identifiersidentifier_casez/change case of identifiers, CHOICE is one of {}c              3   (   K   | ]
  }d | d   ywr   r   r    s     r#   r$   z create_parser.<locals>.<genexpr>O   r%   r&   z-lz
--languageLANGoutput_formatpythonphpzJoutput a snippet in programming language LANG, choices are "python", "php"z--strip-commentsstrip_commentszremove commentsz-rz
--reindentreindentzreindent statementsz--indent_widthindent_width   z(indentation width (defaults to 2 spaces))r   r   typer   z--indent_after_firstindent_after_firstz2indent after first line of statement (e.g. SELECT)z--indent_columns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_after
wrap_afterr   z*Column after which lists should be wrappedz--comma_first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_groupformatjoinintbool)_CASE_CHOICESparsergroups      r#   create_parserrF      s   4M$$*2	F 4  6
 k8	  : ?  A $$  &
 %%&:;E	l;BBII6668  9 
o>EEII6668  9 
l5!+  , 
    
l"  $ 
7  9 
!A  C 
K  M 
"4	  6 
,9	  ; 
9  ; 
<  > 
A  C 
9	  ; M    c                 J    t         j                  j                  d|  d       y)z5Print msg and optionally exit with return code exit_.z[ERROR] 
   )sysstderrwrite)msgs    r#   _errorrO      s     JJxuB'(rG   c                    | dk(  r|j                   rt        d      S | dk(  rQt        t        j                  j
                  |j                        }	 |j                         }|j                          n@	 t        | |j                        5 }dj                  |j                               }ddd       d}|j                   r	 t        | d	|j                        }d
}nB|j                  r&	 t        |j                  d	|j                        }d
}nt        j                  }t        |      }	 t         j"                  j%                  |      }t!        j(                  fi |}	|j+                  |	       |j-                          |r|j/                          y# |j                          w xY w# 1 sw Y   xY w# t        $ r}t        d|  d|       cY d}~S d}~ww xY w# t        $ r}t        d|  d|       cY d}~S d}~ww xY w# t        $ r%}t        d|j                   d|       cY d}~S d}~ww xY w# t&        $ r}t        d|       cY d}~S d}~ww xY w)zdProcess a single file with the given formatting options.

    Returns 0 on success, 1 on error.
    -z Cannot use --in-place with stdin)r8    NzFailed to read z: FwTzFailed to open zInvalid options: r   )r   rO   r   rK   stdinbufferr8   readdetachopenr@   	readlinesOSErrorr   stdoutvarsr<   	formattervalidate_optionsr   r?   rM   flushclose)
r   argswrapperdatafeclose_streamstreamformatter_optsss
             r#   _process_filerj      s     34<<899 3		 0 04==I	<<>DNN	=h71wwq{{}- 8 L||	=(C$--@FL 
	A$,,dmmDFL  $ZN/!++<<^L 	//A
LLO
LLNK NN 87 	=OH:Rs;<<	=  	=OH:Rs;<<	=  	AODLL>A3?@@	A  /)!-../s   F 4F5  F)+F5 G *$H +H4 F&)F2.F5 5	G>GGG	H %G;5H ;H 	H1H,&H1,H14	I=I
IIc                    t               }|j                  |       } t        | j                        dkD  r.| j                  rt        d      S | j                  st        d      S d}| j                  D ]  }t        ||       }|dk7  s|} |S )NrJ   z+Cannot use -o/--outfile with multiple filesz&Multiple files require --in-place flagr   )rF   
parse_argslenr   r   rO   r   rj   )ra   rD   	exit_coder   results        r#   mainrp      s    _FT"D 4==A<<GHH||BCC IMMx.Q;I " rG   )N)__doc__r9   rK   ior   r<   sqlparse.exceptionsr   rF   rO   rj   rp   r   rG   r#   <module>rt      s2     
   -
EP4nrG   