3
d}                 @   s   d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
 edd	gd
ZedddZejddddZejddddZejdddZdd ZG dd dejZG dd dejZdd ZdS )z"
Utilities for the CLI functions.
    N   )import_module   )InputMultiPathtraits)get_trait_descz-hz--help)Zhelp_option_namesT)Zallow_extra_argsZignore_unknown_optionsF)existsZ	file_okayresolve_path)r   dir_okayr	   )r
   r	   c             C   s   |d krt jdj||S )Nzgot {}.)clickZBadParameterformat)ctxparamvalue r   6/tmp/pip-build-7vycvbft/nipype/nipype/scripts/utils.pycheck_not_none   s    r   c               @   s   e Zd ZdZdd ZdS )RegularExpressionregexc             C   sB   yt j|t j}W n& tk
r8   | jd| || Y nX |S d S )Nz%%s is not a valid regular expression.)recompile
IGNORECASE
ValueErrorfail)selfr   r   r   Zrexr   r   r   convert$   s
    zRegularExpression.convertN)__name__
__module____qualname__namer   r   r   r   r   r   !   s   r   c               @   s   e Zd ZdZdd ZdS )PythonModulezPython module pathc             C   s<   yt |}W n& tk
r2   | jd| || Y nX |S d S )Nz %s is not a valid Python module.)r   r   r   )r   r   r   r   moduler   r   r   r   0   s
    zPythonModule.convertN)r   r   r   r   r   r   r   r   r   r    -   s   r    c       	      C   s^  |j  }xNt|jjddj D ]2\}}djt|||t|d d }|jdd}i }d}|j	tj
rt|||d< d	|d
< |js|j	tjst|jj}|ttttfkr|tkrt}||d< nnt|jdkrt|jd jj}|tkrt}|tttttfkr6||d< n"t|jdkr6|j	tjs6d}t|ddr|j	trZd|d< nZ|j	tjr|jj|jjkr|jjr|jj|d< nd|d< n|j	tjrtj|d< |rtdj|| j|fd|i| q"|j	trd|d< n@|j	tjr6|jj|jjkr.|jjr.|jj|d< nd|d< |s"| jd| f||d| q"W | S )z>Add arguments to `arg_parser` to create a CLI for `interface`.N)Z	transient
r   %z%%Fdefault
store_trueactiontyper   r   T	mandatory+nargszThis interface cannot be used. via the command line as multiple inner traits are currently not supported for mandatory argument: {}.help*z--%s)destr+   ) Z
input_specsortedinputsr   itemsjoinr   lenreplaceZis_trait_typeZBoolgetattrZinner_traitsZTraitCompoundr'   
trait_typedefault_valuebytesstrintfloatboolDictr   ListZminlenmaxlenjsonloadsNotImplementedErrorr   add_argument)	Z
arg_parserZ	interfacer/   r   specdescargsZhas_multiple_inner_traitsr5   r   r   r   add_args_options9   sd    $"







 rF   )__doc__r   r   r?   instancer   Zinterfaces.baser   r   Zinterfaces.base.supportr   dictZCONTEXT_SETTINGSZUNKNOWN_OPTIONSPathZExistingDirPathZExistingFilePathZUnexistingFilePathr   Z	ParamTyper   r    rF   r   r   r   r   <module>   s   