Your IP : 216.73.216.213
B
�d{T� � @ s^ d Z ddlmZ dZddlmZmZ eed�s4ee_ d
dd�Z
G d d
� d
�ZG dd� d�ZdS )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�_Nc C s� y|ddl }|�d� |�| � |�� �dd�}|�|� |dk rzy|�|� W n tk
rb Y nX ddl}|� |j
|� W n td� Y nX dS )z'Init the readline library if available.r Nz
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_readline7 s
r c @ s e Zd ZdZdd� Zdd� ZdS )� CompleterzReadline completer.c C s
|| _ d S )N)�list)�self�commandsr r r �__init__M s zCompleter.__init__c C sX t |�}g }x(| jD ]}|d|� |kr|�|� qW y|| S tk
rR dS X dS )z.Hook called by readline when <tab> is pressed.N)�lenr �append�
IndexError)r �text�state�n�matches�cmdr r r �completeP s zCompleter.completeN)�__name__�
__module__�__qualname__�__doc__r r# r r r r r J s r c @ sx e Zd ZdZed�ed�d�ZdZddd�Zdd � Zd
d� Z dd
� Z
dd� Zddd�Zdded�fZ
dd� Zdd� ZdS )� CLIHelperzgAn abstract command line interface client which recognize commands
and provide an help system.
ZOthers)�help�quitr Nc C s, i | _ d | _t| �� �| _t| jj|� d S )N)�_topicsr r �_register_commandsZ
_completerr r# )r r r r r r g s zCLIHelper.__init__c C s� x�yt d�}W n tk
r( t P Y nX |�� }|s8q|�� }|d | jkr�y,d| j|d }t| |�|dd� � W q� tk
r� P Y q� ddl}|�� Y q�X qy| � |� W q ddl}|�� Y qX qW dS )zloop on user input, exit on EOFz>>> r zdo_%s� N)
r �EOFErrorr �strip�splitr �getattr� traceback� print_exc�handle_line)r �lineZs_line�argsr"