Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/cli.cpython-37.pyc

B

�d{T��@s^dZddlmZdZddlmZmZeed�s4ee_	d
dd�Z
Gd	d
�d
�ZGdd�d�ZdS)a#Command line interface helper classes.

It provides some default commands, a help system, a default readline
configuration with completion and persistent history.

Example::

    class BookShell(CLIHelper):

        def __init__(self):
            # quit and help are builtins
            # CMD_MAP keys are commands, values are topics
            self.CMD_MAP['pionce'] = _("Sommeil")
            self.CMD_MAP['ronfle'] = _("Sommeil")
            CLIHelper.__init__(self)

        help_do_pionce = ("pionce", "pionce duree", _("met ton corps en veille"))
        def do_pionce(self):
            print('nap is good')

        help_do_ronfle = ("ronfle", "ronfle volume", _("met les autres en veille"))
        def do_ronfle(self):
            print('fuuuuuuuuuuuu rhhhhhrhrhrrh')

    cl = BookShell()
�)�print_functionzrestructuredtext en)�builtins�input�_NcCs�y|ddl}|�d�|�|�|���dd�}|�|�|dk	rzy|�|�Wntk
rbYnXddl}|�	|j
|�Wntd�YnXdS)z'Init the readline library if available.rNz
tab: complete�:�zreadline is not available :-()�readline�parse_and_bindZ
set_completerZget_completer_delims�replaceZset_completer_delims�read_history_file�IOError�atexit�register�write_history_file�print)Zcomplete_method�histfiler�stringr
�r�C/opt/alt/python37/lib/python3.7/site-packages/logilab/common/cli.py�
init_readline7s


rc@s eZdZdZdd�Zdd�ZdS)�	CompleterzReadline completer.cCs
||_dS)N)�list)�self�commandsrrr�__init__MszCompleter.__init__cCsXt|�}g}x(|jD]}|d|�|kr|�|�qWy||Stk
rRdSXdS)z.Hook called by readline when <tab> is pressed.N)�lenr�append�
IndexError)r�text�state�n�matches�cmdrrr�completePszCompleter.completeN)�__name__�
__module__�__qualname__�__doc__rr#rrrrrJsrc@sxeZdZdZed�ed�d�ZdZddd�Zdd	�Zd
d�Z	dd
�Z
dd�Zddd�Zdded�fZ
dd�Zdd�ZdS)�	CLIHelperzgAn abstract command line interface client which recognize commands
    and provide an help system.
    ZOthers)�help�quitrNcCs,i|_d|_t|���|_t|jj|�dS)N)�_topicsrr�_register_commandsZ
_completerrr#)rrrrrrgszCLIHelper.__init__cCs�x�ytd�}Wntk
r(tPYnX|��}|s8q|��}|d|jkr�y,d|j|d}t||�|dd��Wq�tk
r�PYq�ddl}|��Yq�Xqy|�	|�Wqddl}|��YqXqWdS)zloop on user input, exit on EOFz>>> rzdo_%s�N)
r�EOFErrorr�strip�splitr�getattr�	traceback�	print_exc�handle_line)r�lineZs_line�argsr"r2rrr�runms0z
CLIHelper.runcCs
t��dS)zgMethod to overload in the concrete class (should handle
        lines which are not commands).
        N)�NotImplementedError)rZ
stripped_linerrrr4�szCLIHelper.handle_linecCs|i|_i|_dd�t|�D�}xR|D]J}|j|}t|d|�}|j�|g��|�||j|j|<||j|<q$W|j�	�S)zY register available commands method and return the list of
        commands name
        cSs(g|] }|dd�dkr|dd��qS)N�Zdo_r)�.0�attrrrr�
<listcomp>�sz0CLIHelper._register_commands.<locals>.<listcomp>z
help_do_%s)
r�
_command_help�dir�CMD_MAPr1r+�
setdefaultr�
CMD_PREFIX�keys)rr�command�topicZhelp_methodrrrr,�s

zCLIHelper._register_commandscCs4ttd�|�ttd�|�td|�t�dS)Nz
Command %sz
Syntax: %s�	)rr)rr"ZsyntaxZexplanationrrr�_print_help�s
zCLIHelper._print_helpcCs6||jkr|j|j|��n|dks0||jkr�ttd��ttd��t|j���}x|D]}td|�q\Wt�ttd��|j��}|��x�|D]}td|t	|j
�d��q�Wnxttd�|�txb|j|D]T}y$t|�r�|j|��n
|j|�Wq�ddl}|�
�td|j�Yq�Xq�WdS)	zbase input of the help systemNz#Use help <topic> or help <command>.zAvailable topics are:rEzAvailable commands are:zAvailable commands about %s:rzERROR in help method %s)r=rFr+rr�sortedrBr�sortrrA�callabler2r3r$)rrCZtopicsrDrZcommand_help_methodr2rrr�do_help�s4



zCLIHelper.do_helpr)zhelp [topic|command]zSprint help message for the given topic/command or available topics when no argumentcCs
t��dS)zquit the CLIN)r.)rrrr�do_quit�szCLIHelper.do_quitcCsddtd�fS)Nr*zquit the application)r)rrrr�help_do_quit�szCLIHelper.help_do_quit)N)N)r$r%r&r'rr?rArr7r4r,rFrJZhelp_do_helprKrLrrrrr(]s
		
 r()N)
r'�
__future__r�
__docformat__Z	six.movesrr�hasattr�strrrrr(rrrr�<module>+s