
    \O                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKr/ SQr " S S\R,                  5      r " S S\R,                  5      r " S S\R,                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\R,                  5      r " S S\R,                  5      rg) zA collection of CLI walkers.    )absolute_import)division)unicode_literalsN)actions)arg_parsers)cli_tree)markdown)walker)
properties)render_document)files)pkg_resources)zfavicon.icoz
index.htmlz
_menu_.cssz	_menu_.jsz_title_.htmlc                   F   ^  \ rS rSrSrSrSr S	U 4S jjrS rS r	Sr
U =r$ )
DevSiteGenerator.   a  Generates DevSite reference HTML in a directory hierarchy.

This implements gcloud meta generate-help-docs --manpage-dir=DIRECTORY.

Attributes:
  _directory: The DevSite reference output directory. _need_section_tag[]:
    _need_section_tag[i] is True if there are section subitems at depth i.
    This prevents the creation of empty 'section:' tags in the '_toc' files.
  _toc_root: The root TOC output stream.
  _toc_main: The current main (just under root) TOC output stream.
z/sdk/gcloud/referencez	_toc.yamlc                    > [         [        U ]  XS9  X l        [        R
                  " U R                  5        / U l        [        R                  R                  U R                  U R                  5      n[        R                  " U5      U l        U R                  R                  S5        U R                  R                  S5        U R                  R                  SU R                  -  5        U R                  R                  S5        SU l        g)a  Constructor.

Args:
  cli: The Cloud SDK CLI object.
  directory: The devsite output directory path name.
  hidden: Boolean indicating whether to consider the hidden CLI.
  progress_callback: f(float), The function to call to update the progress
    bar or None for no progress bar.
  restrict: Restricts the walk to the command/group dotted paths in this
    list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
    restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
    commands/groups.
restricttoc:
z- title: "gcloud Reference"
  path: %s
z  section:
N)superr   __init__
_directoryr   MakeDir_need_section_tagospathjoin_TOC
FileWriter	_toc_rootwrite
_REFERENCE	_toc_main)selfcli	directoryhiddenprogress_callbackr   toc_path	__class__s          *lib/googlecloudsdk/calliope/walker_util.pyr   DevSiteGenerator.__init__>   s      

D*3*BO	MM$//"Dww||DOOTYY7H%%h/DNNN"NN89NN$//9:NN(DN    c           	      B  ^ ^^	^
 U	U
UU 4S jnUR                  5       m	T(       aD  [        R                  R                  " T R                  /T	SS Q76 m
[
        R                  " T
SS9  O.[        R                  R                  " T R                  /T	SS Q76 m
[        R                  R                  T
T(       a  SOT	S   5      S-   nSn[        R                  R                  R                  R                  5       (       a2  [        R                  R                  R                  R                  5       n[        R                  R                  R                  R                  S	5        [
        R                  " U5       n[        R                   " U5      n["        R$                  " S
SR                  T	5      [&        R(                  " U5      UUS9  SSS5        [        R                  R                  R                  R                  U5        U" 5         U$ ! , (       d  f       NJ= f)a)  Updates the TOC and Renders a DevSite doc for each node in the CLI tree.

Args:
  node: group/command CommandCommon info.
  parent: The parent Visit() return value, None at the top level.
  is_group: True if node is a group, otherwise its is a command.

Returns:
  The parent value, ignored here.
c            
        > [        T5      S-
  n U (       d  gSR                  T5      nU [        TR                  5      :  a6  TR                  R                  S5        U [        TR                  5      :  a  M6  U S:X  Ga?  T(       a  TR                  (       a  TR                  R                  5         [        R                  R                  TTR                  5      n[        R                  " U5      nUTl        UR                  S5        UR                  SU-  5        UR                  SSR                  TR                  /TSS -   5      -  5        S	TR                  U '   TR                  nS
nT(       aH  UR                  U< SSR                  TR                  /TSS -   TR                  /-   5      < S35        gOVTR                  nS
U S-
  -  nTR                  U S-
     (       a&  STR                  U S-
  '   UR                  SU-  5        TS   nUR                  U< SU< S35        UR                  U< SSR                  TR                  /TSS -   5      < S35        TTR                  U '   g)zUpdates the DevSIte TOC.   N Fr   z- title: "%s"
r   /Tz  z- include: 
z%ssection:
z
- title: "z"
z  path: )lenr   r   appendr$   closer   r   r   r   r    r"   r#   r!   )	depthtitler*   tocindentcommandr'   is_groupr%   s	        r,   
_UpdateTOC*DevSiteGenerator.Visit.<locals>._UpdateTOCf   s   'lQehhweS//00%%e, S//00	!^^NN  "WW\\)TYY7(  *#$.
))H

))%-
.
))NSXXt.?'!"+.M%NN
O*.$
 
 
'nn
)) ((DOO,wqr{:dii[HI   nn#!!%!),.3$
 
 
+
))NV+
,	iivu56	ii$chh/@712;/N&O
P '/dU#r.   r1   N  moder5   index.htmluniversedevsiter2   )styler:   finoutcommand_node)GetPathr   r   r   r   r   r   r   VALUEScoreuniverse_domainIsExplicitlySetGetSetr    r	   Markdownr   RenderDocumentioStringIO)r%   nodeparentr>   r?   r   rO   fmdr=   r'   s   `  `     @@r,   VisitDevSiteGenerator.VisitZ   s   ,/ ,/^ llnG'',,t==immIE*'',,t?2?i 	Y8EO 	 O--==??"))..>>BBDo**..z:			$	1T"b$$!kk"o 
  **..?LM 
 	s   :AH
Hc                     U R                   R                  5         U R                  (       a  U R                  R                  5         gg)z5Closes the TOC files after the CLI tree walk is done.N)r!   r8   r$   )r%   s    r,   DoneDevSiteGenerator.Done   s.    NN~~
nn r.   )r   r   r$   r!   FNN)__name__
__module____qualname____firstlineno____doc__r#   r   r   r[   r^   __static_attributes____classcell__r+   s   @r,   r   r   .   s1    
 '*	$ LP8]~ r.   r   c                   8   ^  \ rS rSrSr SU 4S jjrS rSrU =r$ )HelpTextGenerator   zoGenerates help text files in a directory hierarchy.

Attributes:
  _directory: The help text output directory.
c                 v   > [         [        U ]  XUS9  X l        [        R
                  " U R                  5        g)a  Constructor.

Args:
  cli: The Cloud SDK CLI object.
  directory: The Help Text output directory path name.
  hidden: Boolean indicating whether to consider the hidden CLI.
  progress_callback: f(float), The function to call to update the progress
    bar or None for no progress bar.
  restrict: Restricts the walk to the command/group dotted paths in this
    list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
    restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
    commands/groups.
)r)   r   N)r   rj   r   r   r   r   r%   r&   r'   r(   r)   r   r+   s         r,   r   HelpTextGenerator.__init__   s6      

T+8 ,   O	MM$//"r.   c                 P   UR                  5       nU(       a/  [        R                  R                  " U R                  /USS Q76 nO.[        R                  R                  " U R                  /USS Q76 n[
        R                  " USS9  [        R                  R                  XS(       a  SOUS   5      n[
        R                  " U5       n[        R                  " U5      n[        R                  " S[        R                  " U5      US9  SSS5        U$ ! , (       d  f       U$ = f)	a  Renders a help text doc for each node in the CLI tree.

Args:
  node: group/command CommandCommon info.
  parent: The parent Visit() return value, None at the top level.
  is_group: True if node is a group, otherwise its is a command.

Returns:
  The parent value, ignored here.
r1   Nr5   rA   rB   GROUPtext)rH   rI   rJ   )rL   r   r   r   r   r   r   r    r	   rS   r   rT   rU   rV   )	r%   rW   rX   r>   r=   r'   r   rY   rZ   s	            r,   r[   HelpTextGenerator.Visit   s     llnG'',,t==i'',,t?2?i	MM)%(77<<	h7GBKHD			$	1T"b$$6r{{2AN 
  M 
 	 Ms   AD
D%)r   r`   	ra   rb   rc   rd   re   r   r[   rf   rg   rh   s   @r,   rj   rj      s     LP#, r.   rj   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )DocumentGenerator   zGenerates style manpage files with suffix in an output directory.

All files will be generated in one directory.

Attributes:
  _directory: The document output directory.
  _style: The document style.
  _suffix: The output file suffix.
c                    > [         [        U ]  XS9  X l        X0l        X@l        [        R                  " U R                  5        g)a  Constructor.

Args:
  cli: The Cloud SDK CLI object.
  directory: The manpage output directory path name.
  style: The document style.
  suffix: The generate document file suffix. None for .<SECTION>.
  restrict: Restricts the walk to the command/group dotted paths in this
    list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
    restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
    commands/groups.
r   N)r   ru   r   r   _style_suffixr   r   )r%   r&   r'   rH   suffixr   r+   s         r,   r   DocumentGenerator.__init__  s7     

T+C+COKL	MM$//"r.   c           	         U R                   S:X  a  [        R                  " U5      nOSnUR                  5       n[        R
                  R                  U R                  SR                  U5      5      U R                  -   n[        R                  " U5       n[        R                  " U5      n[        R                  " U R                   SR                  U5      [        R                   " U5      UUS9  SSS5        U$ ! , (       d  f       U$ = f)a  Renders document file for each node in the CLI tree.

Args:
  node: group/command CommandCommon info.
  parent: The parent Visit() return value, None at the top level.
  is_group: True if node is a group, otherwise its is a command.

Returns:
  The parent value, ignored here.
linterN_r2   )rH   r:   rI   rJ   command_metadata)rx   r   GetCommandMetaDatarL   r   r   r   r   ry   r   r    r	   rS   r   rT   rU   rV   )	r%   rW   rX   r>   	meta_datar=   r   rY   rZ   s	            r,   r[   DocumentGenerator.Visit  s     {{h,,T2iillnG77<<'):;dllJD			$	1T"b$$!kk"o$ 
  M 
 	 Ms   AC<<
D)r   rx   ry   )Nrs   rh   s   @r,   ru   ru      s    #& r.   ru   c                   >   ^  \ rS rSrSrS rS r SU 4S jjrSrU =r	$ )HtmlGeneratori5  zGenerates HTML manpage files with suffix .html in an output directory.

The output directory will contain a man1 subdirectory containing all of the
HTML manpage files.
c                 v   ^^^ S mUUU4S jmTR                  S5        T" U/ 5        TR                  S5        g)zWrites the command menu tree HTML on out.

Args:
  command: dict, The tree (nested dict) of command/group names.
  out: stream, The output stream.
c                 $    SR                  U 5      $ )Nr~   )r   )r   s    r,   ConvertPathToIdentifier<HtmlGenerator.WriteHtmlMenu.<locals>.ConvertPathToIdentifierD  s    XXd^r.   c           
        > [        U5      nUS::  a  SOSnUS-  S-   nU R                  S5      nX/-   nTR                  SR                  SU-  UUT	" U5      S95        U R                  S	/ 5      U R                  S
/ 5      -   nU(       aq  TR                  S5        [	        US S9 H  nT
" X5        M     TR                  SR                  SUS-   -  S95        TR                  SR                  SU-  S95        gTR                  S5        g)zVisit each command and group in the CLI command tree.

Args:
  command: dict, The tree (nested dict) of command/group names.
  prefix: [str], The subcommand arg prefix.
r1   visibler(      _name_zT{indent}<li class="{visibility}" id="{item}" onclick="select(event, this.id)">{name}r2   )r<   
visibilitynameitemcommandsgroupsz<ul>
c                     U S   $ )Nr    )xs    r,   <lambda>FHtmlGenerator.WriteHtmlMenu.<locals>.WalkCommandTree.<locals>.<lambda>_  s    (r.   )keyz{indent}</ul>
)r<   z{indent}</li>
z</li>
N)r6   getr"   formatsorted)r=   prefixlevelr   r<   r   argsr   cr   WalkCommandTreerJ   s            r,   r   4HtmlGenerator.WriteHtmlMenu.<locals>.WalkCommandTreeG  s    &ke %
9jqy1}f[["df_d	ii44:F6\#*40	 5; 5 Z,w{{8R/HHh			(&;<A
!
" =		#**#!2D*EF		#**#,*?@		)r.   a  <html>
<head>
<meta name="description" content="man page tree navigation">
<meta name="generator" content="gcloud meta generate-help-docs --html-dir=.">
<title> man page tree navigation </title>
<base href="." target="_blank">
<link rel="stylesheet" type="text/css" href="_menu_.css">
<script type="text/javascript" src="_menu_.js"></script>
</head>
<body>

<div class="menu">
 <ul>
z </ul>
</div>

</body>
</html>
N)r"   )r%   r=   rJ   r   r   s     `@@r,   WriteHtmlMenuHtmlGenerator.WriteHtmlMenu<  s=    > II   GR II  r.   c                    [        U5      R                  X45      n[        R                  " [        R
                  R                  US5      5       nU R                  XV5        SSS5        [         HN  n[        R                  " SU5      n[        R                  " [        R
                  R                  X5      U5        MP     g! , (       d  f       Ng= f)z&Generates html nav files in directory.z_menu_.htmlNz+googlecloudsdk.api_lib.meta.help_html_data.)CommandTreeGeneratorWalkr   r    r   r   r   r   _HELP_HTML_DATA_FILESr   GetResourceWriteBinaryFileContents)	r%   r'   r&   r(   r   treerJ   	file_namefile_contentss	            r,   _GenerateHtmlNavHtmlGenerator._GenerateHtmlNav~  s    $))&;D			"'',,y-@	AS
# 
B*	#//
7m ##
'',,y
,m	 + 
B	As   C
Cc                 T   > [         [        U ]  UUSSUS9  U R                  X!X55        g)a  Constructor.

Args:
  cli: The Cloud SDK CLI object.
  directory: The HTML output directory path name.
  hidden: Boolean indicating whether to consider the hidden CLI.
  progress_callback: f(float), The function to call to update the progress
    bar or None for no progress bar.
  restrict: Restricts the walk to the command/group dotted paths in this
    list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
    restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
    commands/groups.
htmlrE   r'   rH   rz   r   N)r   r   r   r   rm   s         r,   r   HtmlGenerator.__init__  s:      
-' (  	)&;r.   r   r`   )
ra   rb   rc   rd   re   r   r   r   rf   rg   rh   s   @r,   r   r   5  s%    @D LP< <r.   r   c                   6   ^  \ rS rSrSrSr SU 4S jjrSrU =r$ )ManPageGeneratori  zGenerates manpage files with suffix .1 in an output directory.

The output directory will contain a man1 subdirectory containing all of the
manpage files.
zman{section}c                    > U R                   R                  SS9n[        R                  R	                  X&5      n[
        [        U ]  XSSUS9  g)a  Constructor.

Args:
  cli: The Cloud SDK CLI object.
  directory: The manpage output directory path name.
  hidden: Boolean indicating whether to consider the hidden CLI.
  progress_callback: f(float), The function to call to update the progress
    bar or None for no progress bar.
  restrict: Restricts the walk to the command/group dotted paths in this
    list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
    restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
    commands/groups.
r1   )sectionmanz.1r   N)_SECTION_FORMATr   r   r   r   r   r   r   )	r%   r&   r'   r(   r)   r   section_subdirsection_dirr+   s	           r,   r   ManPageGenerator.__init__  sN    $ ))000;N'',,y9K	
D*%x + r.   r   r`   )	ra   rb   rc   rd   re   r   r   rf   rg   rh   s   @r,   r   r     s      #/ LP r.   r   c                   2   ^  \ rS rSrSr SU 4S jjrSrU =r$ )LinterGeneratori  z@Generates linter files with suffix .json in an output directory.c                 0   > [         [        U ]  UUSSUS9  g)a  Constructor.

Args:
  cli: The Cloud SDK CLI object.
  directory: The linter output directory path name.
  hidden: Boolean indicating whether to consider the hidden CLI.
  progress_callback: f(float), The function to call to update the progress
    bar or None for no progress bar.
  restrict: Restricts the walk to the command/group dotted paths in this
    list. For example, restrict=['gcloud.alpha.test', 'gcloud.topic']
    restricts the walk to the 'gcloud topic' and 'gcloud alpha test'
    commands/groups.
r}   z.jsonr   N)r   r   r   rm   s         r,   r   LinterGenerator.__init__  s(    " 
/4) * r.   r   r`   )ra   rb   rc   rd   re   r   rf   rg   rh   s   @r,   r   r     s    H LP r.   r   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r   i  aS  Constructs a CLI command dict tree.

This implements the resource generator for gcloud meta list-commands.

Attributes:
  _with_flags: Include the non-global flags for each command/group if True.
  _with_flag_values: Include flag value choices or :type: if True.
  _global_flags: The set of global flags, only listed for the root command.
c                 z   > [         [        U ]
  " U40 UD6  U=(       d    UU l        X0l        [        5       U l        g)a  Constructor.

Args:
  cli: The Cloud SDK CLI object.
  with_flags: Include the non-global flags for each command/group if True.
  with_flag_values: Include flags and flag value choices or :type: if True.
  **kwargs: Other keyword arguments to pass to Walker constructor.
N)r   r   r   _with_flags_with_flag_valuesset_global_flags)r%   r&   
with_flagswith_flag_valueskwargsr+   s        r,   r   CommandTreeGenerator.__init__  s8     

.s=f=!5%5D-Dr.   c           	      D   UR                   R                  SS5      nSU0nU R                  (       GaG  / nUR                  5        GH  nSnU R                  (       GaF  UR
                  (       aT  [        UR
                  5      n	U	SS/:w  a6  SR                  U	 V
s/ s H  n
[        R                  " U
5      PM     sn
5      nO[        UR                  [        5      (       a  SnO[        UR                  [        5      (       a  S	nO[        UR                  [        R                  5      (       a  S
nOq[        UR                  [        R                   5      (       a  SnOEUR"                  S:w  a5  UR$                  =(       d    UR&                  R)                  5       nSU-   S-   nUR*                   H#  nU(       a  USU-   -  nUR-                  U5        M%     GM     Sn/ nU HT  nXR.                  ;   a  M  UR1                  U5      (       a  SU[3        U5      S -   nUU;   a  MC  UR-                  U5        MV     U(       a:  [        U5      US'   U R.                  (       d  U R.                  R5                  U5        U(       aR  U(       aI  [6        R8                  U;  a  / U[6        R8                  '   U[6        R8                     R-                  U5        U$ [6        R:                  U;  a  / U[6        R:                  '   U[6        R:                     R-                  U5        gs  sn
f )aC  Visits each node in the CLI command tree to construct the dict tree.

Args:
  node: group/command CommandCommon info.
  parent: The parent Visit() return value, None at the top level.
  is_group: True if node is a group, otherwise its is a command.

Returns:
  The subtree parent value, used here to construct a dict tree.
r~   -r   Nfalsetrue,z:int:z:float:z:dict:z:list:r   :=z--no-z--_flags_)r   replacer   GetAllAvailableFlagsr   choicesr   r   six	text_type
isinstancetypeintfloatr   ArgDictArgListnargsmetavardestupperoption_stringsr7   r   
startswithr6   updater   LOOKUP_GROUPSLOOKUP_COMMANDS)r%   rW   rX   r>   r   info	all_flagsargvaluer   choicer   rY   	no_prefixflagsflagpositives                    r,   r[   CommandTreeGenerator.Visit  s|    99S#&DdDi**,#!!![[S[[)G7F++hhGLG&f 5GLMe#((C((E#((E**E#((K$7$788E#((K$7$788EyyA~kk5SXX^^%5G'MC'E##AuA


1
 $% -, ie$%%%
??9%%DY!122("T  
 -Y!! 


#
#E
*	!!/+-&''
(x%%&--d3kv-)+fX%%&
8##$++D1Y  Ms    L
)r   r   r   )FFrs   rh   s   @r,   r   r     s    A Ar.   r   c                       \ rS rSrSrS rSrg)GCloudTreeGeneratoriA  zGenerates an external representation of the gcloud CLI tree.

This implements the resource generator for gcloud meta list-gcloud.
c                 .    [         R                  " X5      $ )aO  Visits each node in the CLI command tree to construct the external rep.

Args:
  node: group/command CommandCommon info.
  parent: The parent Visit() return value, None at the top level.
  is_group: True if node is a group, otherwise its is a command.

Returns:
  The subtree parent value, used here to construct an external rep node.
)r   Command)r%   rW   rX   r>   s       r,   r[   GCloudTreeGenerator.VisitG  s     D))r.   r   N)ra   rb   rc   rd   re   r[   rf   r   r.   r,   r   r   A  s    
*r.   r   )re   
__future__r   r   r   rU   r   googlecloudsdk.callioper   r   r   r	   r
   googlecloudsdk.corer   &googlecloudsdk.core.document_renderersr   googlecloudsdk.core.utilr   r   r   r   Walkerr   rj   ru   r   r   r   r   r   r   r.   r,   <module>r      s     # &  ' 	 	 + / , , * * B * 2 
 Ov}} Od6 6r9 9xm<% m<`( D' :Z6== Zz*&-- *r.   