3
_Afe                 @   sn   d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
mZmZmZ d dlZG dd de
eZdS )    )print_functionN)AbstractFormatter
DumbWriter)Coloring)PagedCommandMirrorSafeCommandGitcAvailableCommandGitcClientCommandc               @   sV   e Zd ZdZdZdZdZdd Zdd Zd	d
 Z	dddZ
dd Zdd Zdd ZdS )HelpFz"Display detailed help on a commandz
%prog [--all|command]
z6
Displays detailed usage information about a command.
c             C   s|   d}x|D ]}t |t|}q
W d| }xN|D ]F}| j| }y|jj }W n tk
rb   d}Y nX t|||f  q.W dS )z+Helper to display |commandNames| summaries.r   z  %%-%ds  %%s N)maxlencommandshelpSummarystripAttributeErrorprint)selfcommandNamesmaxlennamefmtcommandZsummary r   >/home/qytech/356xLinux510-101server/.repo/repo/subcmds/help.py_PrintCommands%   s    



zHelp._PrintCommandsc             C   s4   t d t d tt| j}| j| t d d S )Nzusage: repo COMMAND [ARGS]z2The complete list of recognized repo commands are:zESee 'repo help <command>' for more information on a specific command.)r   listsortedr   r   )r   r   r   r   r   _PrintAllCommands4   s
    
zHelp._PrintAllCommandsc                sR   t d t d fdd tt fddjj D }j| t d d S )Nzusage: repo COMMAND [ARGS]z)The most commonly used repo commands are:c                sF   t | t rt | t rdS  jjr(dS t | tr6dS tj rBdS dS )NTF)
isinstancer   r	   manifestisGitcClient
gitc_utilsget_gitc_manifest_dir)cmd)r   r   r   gitc_supported@   s    
z1Help._PrintCommonCommands.<locals>.gitc_supportedc                s"   g | ]\}}|j r |r|qS r   )common).0r   r   )r%   r   r   
<listcomp>K   s   z-Help._PrintCommonCommands.<locals>.<listcomp>zSee 'repo help <command>' for more information on a specific command.
See 'repo help --all' for a complete list of recognized commands.)r   r   r   r   itemsr   )r   r   r   )r%   r   r   _PrintCommonCommands<   s    
zHelp._PrintCommonCommandsr   c                sH   G  fdddt }|| jj}|jdd  jj  |jdd d S )Nc                   s"   e Zd Zdd Z fddZdS )z$Help._PrintCommandHelp.<locals>._Outc             S   s.   t j| |d | jddd| _tt | _d S )Nhelpheadingbold)attr)r   __init__printerr,   r   r   wrap)r   gcr   r   r   r/   V   s    z-Help._PrintCommandHelp.<locals>._Out.__init__c                s  yt  |}W n tk
r"   d S X |dks4|d kr8d S | j  | jd| | j  | j  d j }|j }|jd|}tjd}x|j	dD ]x}|j
dr| jd| | j  | j  q|j|}|r| jd|jd	 | j  | j  q| jj| | jjd	 qW | jjd
 d S )Nr   z%s%szrepo %sz%progz^\n?#+ (.+)$z

 z%s   r   )getattrr   nlr,   NAMEr   replacerecompilesplit
startswithwritematchgroupr1   Zadd_flowing_dataZend_paragraph)r   r,   ZbodyAttrbodymeZasciidoc_hdrZparam)r$   header_prefixr   r   _PrintSection\   s:    



z2Help._PrintCommandHelp.<locals>._Out._PrintSectionN)__name__
__module____qualname__r/   rD   r   )r$   rC   r   r   _OutU   s   rH   ZSummaryr   ZDescriptionhelpDescription)r   r    globalConfigrD   OptionParser
print_help)r   r$   rC   rH   outr   )r$   rC   r   _PrintCommandHelpT   s
    ,
zHelp._PrintCommandHelpc             C   s>   x8t | jD ]*}| j| }| j|_| j|d|f d qW d S )Nz[%s] )rC   )r   r   r    rN   )r   r   r$   r   r   r   _PrintAllCommandHelp   s    
zHelp._PrintAllCommandHelpc             C   s*   |j dddddd |j dddd	d d S )
Nz-az--allshow_all
store_truez"show the complete list of commands)destactionr+   z
--help-allshow_all_helpzshow the --help of all commands)
add_option)r   pr   r   r   _Options   s    zHelp._Optionsc             C   s   t |dkr6|jr| j  q|jr,| j  q| j  nrt |dkr|d }y| j| }W n0 tk
r   td| t	j
d t	jd Y nX | j|_| j| n
| j|  d S )Nr   r4   z!repo: '%s' is not a repo command.)file)r   rT   rO   rP   r   r*   r   KeyErrorr   sysstderrexitr    rN   )r   optargsr   r$   r   r   r   Execute   s     


zHelp.ExecuteN)r   )rE   rF   rG   r&   r   	helpUsagerI   r   r   r*   rN   rO   rW   r_   r   r   r   r   r
      s   
2r
   )
__future__r   r9   rZ   	formatterr   r   colorr   r   r   r   r   r	   r"   r
   r   r   r   r   <module>   s   