o
    $xa                     @   sh   d Z ddlZddlmZ ddlZddlmZ ddlmZ dZ	dd Z
ejfd	d
Zedkr2e  dS dS )zt
This module provides command-line access to pystache.

Run this script using the -h option for command-line help.

    N)OptionParser)TemplateNotFoundError)Rendererz%prog [-h] template context

Render a mustache template with the given context.

positional arguments:
  template    A filename or template string.
  context     A filename or JSON string.c              
   C   s   | dd }t |d}||\}}z	|\}}W ||fS  ty: } ztd|  td W Y d}~||fS d}~w tyX } ztd|  td W Y d}~||fS d}~ww )z1
    Return an OptionParser for the script.

       N)usagez	ERROR: %s)r   
parse_args
ValueErrorprintexitUnboundLocalError)sys_argvr   argsparseroptionstemplatecontexte r   :/usr/lib/python3/dist-packages/pystache/commands/render.pyr   &   s"   

r   c                 C   s   t | t\}}|dr|d d }t }z||}W n	 ty%   Y nw z	tt|}W n t	y=   t
|}Y nw |||}t| d S )Nz	.mustachei)r   USAGEendswithr   Zload_templater   jsonloadopenIOErrorloadsZrenderr	   )r   r   r   ZrendererZrenderedr   r   r   mainA   s    
r   __main__)__doc__r   Zoptparser   sysZpystache.commonr   Zpystache.rendererr   r   r   argvr   __name__r   r   r   r   <module>   s   

