o
    .&ßa  ã                   @   sô   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ e e¡Zeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ de
ƒZ dS )é    N)Úget_global_history_recorder)ÚProfileNotFound)Úsqlite3)ÚBasicCommand)ÚHISTORY_FILENAME_ENV_VAR)ÚDEFAULT_HISTORY_FILENAME)ÚDatabaseConnection)ÚDatabaseRecordWriter)ÚRecordBuilder)ÚDatabaseHistoryHandler)ÚShowCommand)ÚListCommandc                 C   ó   |   dt¡ d S )Nzsession-initialized)ÚregisterÚattach_history_handler©Úevent_handlers© r   úH/usr/lib/python3/dist-packages/awscli/customizations/history/__init__.pyÚregister_history_mode$   ó   ÿr   c                 C   r   )Nzbuilding-command-table.main)r   Úadd_history_commandsr   r   r   r   Úregister_history_commands)   r   r   c                 K   s‚   t | |ƒr?t d¡ tj tt¡}tj 	tj 
|¡¡s$t tj 
|¡¡ t|ƒ}t|ƒ}tƒ }t||ƒ}t |¡ t ¡  d S d S )NzEnabling CLI history)Ú_should_enable_cli_historyÚLOGÚdebugÚosÚenvironÚgetr   r   ÚpathÚisdirÚdirnameÚmakedirsr   r	   r
   r   ÚHISTORY_RECORDERÚadd_handlerÚenable)ÚsessionÚparsed_argsÚkwargsÚhistory_filenameÚ
connectionÚwriterÚrecord_builderÚ
db_handlerr   r   r   r   .   s   

ÿ

òr   c                 C   sb   |j dkrdS z|  ¡ }W n
 ty   Y dS w | d¡dk}|r/td u r/|r-tj d¡ dS |S )NÚhistoryFÚcli_historyÚenabledzRcli_history is enabled but sqlite3 is unavailable. Unable to collect CLI history.
)ÚcommandÚget_scoped_configr   r   r   ÚsysÚstderrÚwrite)r&   r'   Úscoped_configÚhas_history_enabledr   r   r   r   @   s   
ûÿr   c                 K   s   t |ƒ| d< d S )Nr.   )ÚHistoryCommand)Úcommand_tabler&   r(   r   r   r   r   V   s   r   c                   @   s0   e Zd ZdZdZdedœdedœgZdd„ ZdS )	r8   r.   zþCommands to interact with the history of AWS CLI commands ran over time. To record the history of AWS CLI commands set ``cli_history`` to ``enabled`` in the ``~/.aws/config`` file. This can be done by running:

``$ aws configure set cli_history enabled``Úshow)ÚnameÚcommand_classÚlistc                 C   s   |j d u r	tdƒ‚d S )NzVusage: aws [options] <command> <subcommand> [parameters]
aws: error: too few arguments)Ú
subcommandÚ
ValueError)Úselfr'   Úparsed_globalsr   r   r   Ú	_run_mainh   s   
ÿzHistoryCommand._run_mainN)	Ú__name__Ú
__module__Ú__qualname__ÚNAMEÚDESCRIPTIONr   r   ÚSUBCOMMANDSrB   r   r   r   r   r8   Z   s    ÿþr8   )!r   r3   ÚloggingÚbotocore.historyr   Úbotocore.exceptionsr   Úawscli.compatr   Úawscli.customizations.commandsr   Ú'awscli.customizations.history.constantsr   r   Ú awscli.customizations.history.dbr   r	   r
   r   Ú"awscli.customizations.history.showr   Ú"awscli.customizations.history.listr   Ú	getLoggerrC   r   r#   r   r   r   r   r   r8   r   r   r   r   Ú<module>   s.   
