
    $                     .   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZ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Zdd	lmZ dd
lm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Z de z   dz   Z!dZ" G d de      Z#y)&Implementation of gsutil help command.    )absolute_import)print_function)division)unicode_literalsN)PIPE)Popen)Command)OLD_ALIAS_MAP)CommandException)HelpProvider)MAX_HELP_NAME_LEN)	constants)
IS_WINDOWS)IsRunningInteractively)GetTermLines)	text_utilz"
  gsutil help [command or topic]
z
<B>SYNOPSIS</B>
a  


<B>DESCRIPTION</B>
  The following command provides a summary of gsutil commands and additional topics on which
  help is available:

    gsutil help

  The following command provides help about the specified command or topic:

    gsutil help [command or topic]

  The following command provides help about the specified sub-command:

    gsutil help [command] [sub-command]

  For example, running the following provides help about the "set" sub-command of the "acl" command:

    gsutil help acl set

  If you set the PAGER environment variable to the path to a pager program
  (such as /bin/less on Linux), long help sections are piped through
  the specified pager.
zUsage: gsutil [-D] [-DD] [-h header]... [-i service_account] [-m] [-o section:flag=value]... [-q] [-u user_project] [command [opts...] args...]c                       e Zd ZdZ ej
                  dddgeddddd	d
	      Z ej                  ddgdde	i       Z
d Zd Zd Zy)HelpCommandr   help?manr       TF)command_name_aliasesusage_synopsismin_argsmax_argssupported_sub_argsfile_url_okprovider_url_okurls_start_argcommand_helpz"Get help about commands and topics)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textc                 d   | j                         \  }}g }| j                  s|j                  dt        z         dt	        t
              z   dz   }t        |d   d       D ]@  }|j                  ||j                  j                  |j                  j                  fz         B |j                  d       t        |d   d	       D ]@  }|j                  ||j                  j                  |j                  j                  fz         B |j                  d
       nd}| j                  d   }||vr|j                  d|z         n||   }d}t        | j                        dkD  r|j                  j                  }	|	r9| j                  d   |	v r(|dz   | j                  d   z   }|	| j                  d      }
nvd}|	s|j                  d|d|d       nYg }|	D ]  }|j                  d|d|        |j                  d| j                  d   d|d|ddj                  |             |s|s,|j                  j                  }|j                  j                  }
|j                  d       |j                  d|d|j                  j                  d       |j                  d       |j                  
j                  d             t        j                   |dg      d   }|r+d|d|d }|j                  d!       |j                  |       | j#                  d"j                  |             y)#z)Command entry point for the help command.z%s
Available commands:
z  %-zs%s
r#   c                 .    | j                   j                  S N	help_specr$   hps    &platform/gsutil/gslib/commands/help.py<lambda>z(HelpCommand.RunCommand.<locals>.<lambda>r       R\\-C-C    )keyz
Additional help topics:
additional_helpc                 .    | j                   j                  S r,   r-   r/   s    r1   r2   z(HelpCommand.RunCommand.<locals>.<lambda>w   r3   r4   z6
Use gsutil help <command or topic> for detailed help.Fr   zNo help available for "%s"N    TzThe "zV" command has no subcommands. You can ask for the full help by running:

	gsutil help 
z	gsutil help zSubcommand "z" does not exist for command "zT".
You can either ask for the full help about the command by running:

	gsutil help z9

Or you can ask for help about one of the subcommands:

z<B>NAME</B>
z  z - z

z
  The "zT" alias is deprecated, and will eventually be removed completely.
  Please use the "z" command instead.z


<B>DEPRECATION WARNING</B>
r   )_LoadHelpMapsargsappendtop_level_usage_stringstrr   sortedr.   r$   r'   lenr)   joinr(   stripr   get_OutputHelp)selfhelp_type_maphelp_name_mapoutput
format_str	help_provinvalid_subcommandargr$   subcommand_mapr(   subcommand_examples
subcommand	new_aliasdeprecation_warnings                  r1   
RunCommandzHelpCommand.RunCommandj   s   %)%7%7%9"]MF99mm/2HHIC 122W<jmN;"CE)jI$7$7$A$A$-$7$7$M$M$O O 	PE mm12m,=>"CE)jI$7$7$A$A$-$7$7$M$M$O O 	PE mmMN IIaLc	M	!2S89!#&		tyy>A$..CC.		! >c	DIIaL0I&tyy|4I!%!mmEH#OP %'! .*#**,/,= > !/ mm
 yy|S#tyy9L/M	OP "!++55I!++55I
--
(
--"I$7$7$M$MO P
--

--	-
.#''dV4Q7) .1)#= MM>?MM-.RWWV_%r4   c                 @   t         s
t               sDt        j                  dd|      }t        j                  dd|      }t	        j
                  |       yt        j                  dd|      }t        j                  dd|      }t        |j                  d            }dt        j                  v r|t               k\  rt        j                  d   j                  d	      }|d
   j                  d      r|j                  d       	 t        j                  r |j                  t         j"                        }n|}t%        |t&        d      j)                  |       yt	        j
                  |       y# t*        $ r%}t-        dd	j/                  |      d|      d}~ww xY w)zOutputs simply formatted string.

    This function paginates if the string is too long, PAGER is defined, and
    the output is a tty.

    Args:
      help_str: String to format.
    z<B>r   z</B>Nz[1mz[0;0mr:   PAGERr9   r   lessz-rT)stdinuniversal_newlines)inputzUnable to open pager (z): )r   r   resubr   print_to_fdrA   splitosenvironr   endswithr=   sixPY2encoder   UTF8r	   r   communicateOSErrorr   rB   )rF   help_str	num_linespagerinput_for_pageres         r1   rE   zHelpCommand._OutputHelp   sD    /1r8,hH-hH%vveY1Hvvfk84HHNN4()I"**ln!<jj!'',e	q		6	"T	577$OOINN;/$/e4!%	''2{{'I
 H%	  5 # 4 5 	55s   AE/ /	F8 FFc                    t        j                  t        j                  j                        D ]  \  }}}t        d|z          t        j                  t        j                  j                        D ]  \  }}}t        d|z          i }i }t        j                  j                  D ]  }g ||<   	 t        j                  t        j                         t        j                               D ]  }|t        u rt        j                  j                  ||       |||j                  j                   <   |j                  j"                  D ]  }|||<   	 ||j                  j$                     j'                  |        ||fS )a.  Returns tuple of help type and help name.

    help type is a dict with key: help type
                             value: list of HelpProviders
    help name is a dict with key: help command name or alias
                             value: HelpProvider

    Returns:
      (help type, help name)
    zgslib.commands.%szgslib.addlhelp.%s)pkgutiliter_modulesgslibcommands__path__
__import__addlhelphelp_providerALL_HELP_TYPES	itertoolschainr   __subclasses__r
   SanityCheckr.   r$   r%   r&   r=   )rF   _module_namerG   rH   srK   r%   s           r1   r;   zHelpCommand._LoadHelpMaps   sP    %11%..2I2IJ;${23 K %11%..2I2IJ;${23 K MM  //mA 0 __\%@%@%B%,%;%;%=?		g	 	%%i?5>mI''112(22DD
+4'(  EI''11299)D? =))r4   N)__name__
__module____qualname____doc__r
   CreateCommandSpec	_SYNOPSIScommand_specHelpSpec_DETAILED_HELP_TEXTr.   rS   rE   r;    r4   r1   r   r   Q   sr    . +**<
, g@#)BH#&J$*r4   r   )$r   
__future__r   r   r   r   rv   r^   rm   rZ   ra   
subprocessr   r	   gslib.addlhelpro   gslib.commandr
   r   gslib.commandsgslib.exceptionr   gslib.help_providerr   r   gslib.utilsr   gslib.utils.system_utilr   r   r   r   r   r   r>   r   r   r4   r1   <module>r      s    - & %  '  	  	 
    ! '  , , 1 ! . : 0 !	 :Y f*' f*r4   