
    X                     R   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rSSKrSSK	r	SSK
r
SSK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rSrSrSrSr " S S\5      r " S S\5      r " S S\R<                  5      rS r S4S jr!S5S jr"S r#S r$ " S S\	RJ                  5      r&SS\&RN                  S4S jr(S r)S  r*S! r+S6S" jr,S# r-S$ r.S% r/S& r0S' r1        S7S( jr2S4S) jr3 " S* S+\5      r4S, r5\Rl                  4S- jr7S. r8S/ r9S0 r:S1 r;S2 r<S3 r=g)8z/Generate usage text for displaying to the user.    )absolute_import)division)unicode_literalsN)arg_parsers)arg_parsers_usage_text)base)parser_arguments)utilP            c                       \ rS rSrSrS rSrg)HelpInfo.   zCA class to hold some the information we need to generate help text.c                 <    U=(       d    SU l         X l        X0l        g)zCreate a HelpInfo object.

Args:
  help_text: str, The text of the help message.
  is_hidden: bool, True if this command or group has been marked as hidden.
  release_track: calliope.base.ReleaseTrack, The maturity level of this
    command.
 N	help_text	is_hiddenrelease_track)selfr   r   r   s       )lib/googlecloudsdk/calliope/usage_text.py__init__HelpInfo.__init__1   s     _"DNN&    r   N__name__
__module____qualname____firstlineno____doc__r   __static_attributes__ r   r   r   r   .   s
    K'r   r   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
TextChoiceSuggester?   z%Utility to suggest mistyped commands.Nc                 D    0 U l         U(       a  U R                  U5        g g N)_choices
AddChoices)r   choicess     r   r   TextChoiceSuggester.__init__B   s     DM
oog r   c                 T    U H"  nX R                   ;  d  M  X R                   U'   M$     g)z]Add a set of valid things that can be suggested.

Args:
  choices: [str], The valid choices.
Nr*   )r   r,   choices      r   r+   TextChoiceSuggester.AddChoicesJ   s&     	}}	$ !'f	 r   c                 T    U H"  nX0R                   ;  d  M  X R                   U'   M$     g)al  Add an alias that is not actually a valid choice, but will suggest one.

This should be called after AddChoices() so that aliases will not clobber
any actual choices.

Args:
  aliases: [str], The aliases for the valid choice.  This is something
    someone will commonly type when they actually mean something else.
  suggestion: str, The valid choice to suggest.
Nr/   )r   aliases
suggestionaliass       r   
AddAliasesTextChoiceSuggester.AddAliasesV   s$     	mm	#)e r   c           	         U R                   (       d  g[        R                  " UR                  5       U R                    Vs/ s H  n[        R
                  " U5      PM     snS5      nU(       aN  U R                    Vs/ s H$  n[        R
                  " U5      US   :X  d  M"  UPM&     snS   nU R                   U   $ U(       a  U R                   US      $ S$ s  snf s  snf )zFind the item that is closest to what was attempted.

Args:
  arg: str, The argument provided.

Returns:
  str, The closest match.
Nr   r   )r*   difflibget_close_matcheslowersix	text_type)r   argcmatchr0   s        r   GetSuggestion!TextChoiceSuggester.GetSuggestione   s     ==%%		>1cmmA&>E ==I=aCMM!,<a,H=I!Lf]]6""&+4==q"55 ? Js     C
=!C"Cr/   r)   )
r   r   r    r!   r"   r   r+   r6   rA   r#   r$   r   r   r&   r&   ?   s    -
'*6r   r&   c                       \ rS rSrSrg)ArgumentWrapperz   r$   N)r   r   r    r!   r#   r$   r   r   rD   rD   z   s    r   rD   c                 v    [         R                  " S[        R                  S-   [        R                  -   U 5      $ )Nz(\b[a-zA-Z][-a-zA-Z_0-9]*)z\1)resubr   MARKDOWN_ITALIC)msgs    r   _ApplyMarkdownItalicrK   ~   s2    	#
U"T%9%99	
 r   Fc                    U R                   =(       d    U R                  R                  5       nU(       a  [        U5      nU R                  S:X  a  SR                  US9$ U R                  S:X  a  SR                  US9$ U R                  [        R                  :X  a  SR                  US9$ U R                  S:X  a  SR                  US9$ U$ )	zCreate the usage help string for a positional arg.

Args:
  arg: parser_arguments.Argument, The argument object to be displayed.
  markdown: bool, If true add markdowns.

Returns:
  str, The string representation for printing.
+z{var} [{var} ...])var*z[{var} ...]z[-- {var} ...]?z[{var}])metavardestupperrK   nargsformatargparse	REMAINDER)r>   markdownrN   s      r   GetPositionalUsagerY      s     	'sxx~~'#
s
#CYY#%%#%..
yyCC((
yyH&&&""s"++
yyC$$Jr   c                    Uc-  U R                   =(       d    U R                  R                  5       nU(       a  UR                  S5      (       a  SOSn[	        U R
                  [        R                  5      (       a8  U R
                  R                  [        U R                   5      U5      =(       d    UnUS:X  a  gU(       a  [        U5      nUS:X  a  XA-   nSnU R                  S;   a
  SU-   S-   nSnXA-   $ )z-Returns a usage-separator + metavar for flag.--= r   )rP   rO   [])rQ   rR   rS   
startswith
isinstancetyper   ArgTypeUsageGetUsageMetavarboolrK   rT   )flagrQ   namerX   	separators        r   _GetFlagMetavarri      s    _ll/diioo/Gdood33c)		1>>??ii''T\\(:GDOG^"7+G#!GI	ZZ:Gmc!GI		r   c                 j    [        U 5      nUR                  S5      (       a  SU ;  a  SUSS -   S-   nU$ )z0Returns value quoted, with preference for "...".'"r   )reprr`   )valuequoteds     r   _QuoteValuerq      s=    ;&s5 06!B<#%F	-r   c                     U $ )zMockable flag name list filter.r$   )namess    r   _FilterFlagNamesrt      s    	,r   c                        \ rS rSrSrSrSrSrg)InvertedValue   r   r      r$   N)r   r   r    r!   NORMALINVERTEDBOTHr#   r$   r   r   rv   rv      s    &(	
$r   rv   Tc           
      \   U[         R                  L a6  [        U R                  5       Vs/ s H  oUR	                  SSS5      PM     nnO^U[         R
                  L a6  [        U R                  5       Vs/ s H  oUR	                  SSS5      PM     nnO[        U R                  5      n[        U5      nU R                  =(       d    U R                  R                  5       nU(       a  U(       a8   US   nU(       a  U R                  S:X  a  U$ [        XUS9n	SR                  XS	9$ U R                  S:X  aa  U(       aF  S
R                  U Vs/ s H'  n[        R                   U-   [        R                   -   PM)     sn5      n
U
$ S
R                  U5      n
 U
$ / nU H\  n[        XXS9n	UR#                  SR                  U(       a  [        R                   OSUU(       a  [        R                   OSU	S95        M^     S
R                  U5      n
U R$                  (       Gaf  ['        U S['        U SS5      5      (       GdH  [)        U R$                  [*        5      (       a  SR                  U R$                  5      nO[)        U R$                  [,        5      (       a]  SR                  [        [.        R0                  " U R$                  5      5       VVs/ s H  u  pSR                  X5      PM     snn5      nOU R$                  n[3        U5      nU(       a_  [4        R6                  " S[        R                    [        R8                   [        R:                   S3U5      (       a  SR                  U5      nU
SR                  U5      -  n
U
$ s  snf s  snf ! [         a    Sn GNf = fs  snf s  snnf )a'  Returns the usage string for a flag arg.

Args:
  arg: parser_arguments.Argument, The argument object to be displayed.
  brief: bool, If true, only display one version of a flag that has multiple
    versions, and do not display the default value.
  markdown: bool, If true add markdowns.
  inverted: InvertedValue, If INVERTED display the --no-* inverted name. If
    NORMAL display the normal name. If BOTH, display both.
  value: bool, If true display flag name=value for non-Boolean flags.

Returns:
  str, The string representation for printing.
r[   z--[no-]r   --no-r   r   rg   z{flag}{metavar})rf   rQ   , )rg   rX   z{bb}{flag}{be}{flag_metavar})bbrf   beflag_metavaris_requiredrequiredF,z{0}={1}r^   r_   z```{}```z; default={0})rv   r{   sortedoption_stringsreplacerz   rt   rQ   rR   rS   
IndexErrorrT   ri   rU   joinr   MARKDOWN_BOLDappenddefaultgetattrra   listdictr<   	iteritemsrq   rG   searchrI   MARKDOWN_CODE)r>   briefrX   invertedro   xrs   rQ   long_stringr   usage
usage_listrg   r   kvdefault_texts                    r   GetFlagUsager      s   " ###4:3;M;M4NO4NqYYtY*4NEOE=)))289K9K2LM2LQYYtWa(2LEME3%%&E
5
!%KK+388>>+'	%!Hk CIIN"3kBL###KKYY!^ii@E
F14!D$6$66
FeJ 
,C iieB 
,? J$SPl
(
/
/'/##R'/##R'	 0   IIj!E
{{{7]GCU;  
CKK	&	&((3;;'ckk4((((s}}S[[9:
: Q":
 
 ++ )l	biid  !$"6"6!78J8J7K1
M
  "((6%%l33e	,o PM  k G.
s)   N4N/N .N#N(
N N c                 B    U R                   S   R                  SSS5      $ )z(Returns the inverted flag name for flag.r   r[   r}   r   )r   r   )rf   s    r   _GetInvertedFlagNamer     s"    			Q		'	'gq	99r   c                 J    U (       a  U R                  S5      (       a  U $ U S-   $ )N.)endswith)help_messages    r   
_Punctuater     s&    	..s33#r   c                     X;   a  U$ U R                  S5      =n(       a  U US-      S:X  a  U  SU S3$ U R                  S5      S:  a  [        U 5       SU 3$ [        U 5       SU 3$ )z-Appends extra_help_message into help_message.
r   r]   

r   )rfindr   )r   extra_help_messagenewline_indexs      r   _AppendExtraHelpr     s    '%++D111|a8
8 ^4 23266&!A% &'t,>+?@@&'q);(<==r   c                 
   [        U SU R                  5      n[        U5      (       a  U" 5       nU(       a  [        R                  " U5      OSnU R
                  (       a  U$ U R                  (       d  U R                  (       a  SnSnOYU R                  (       a  U R                  n[        U S/ 5      nO. U R                  R                  n[        U R                  S/ 5      n/ n[        U S5      (       a  U R                  u  n  n[        R                  " U5      U;  aj  UR                  SR!                  U5      5        UR"                  (       a9  U R$                  S;   a)  UR                  SR!                  ['        U 5      5      5        OU R                  (       d"  U R                  (       d  U R$                  (       a  OU R"                  S	L a*  UR                  S
R!                  ['        U 5      5      5        OV[)        U [*        R,                  5      (       a7  UR                  SR!                  U R.                  S   ['        U 5      5      5        U(       Ga  U R0                  =(       d    U R2                  R5                  5       n	U	S:w  Gay  [        U SU5      n[7        U5      [7        U5      -
  S:  a  Sn
OSn
[)        U[8        5      (       a  [        R:                  " U5      n[)        U[<        R>                  5      (       d  [A        U5      n/ nU HN  u  pX;   a  M  [        R                  " U5      nSR!                  UUSU[B        -   -  S9nUR                  U5        MP     UR                  SU[B        -   -  5        UR                  SR!                  XSRE                  U5      S95        OWUR                  SR!                  U	U
SRE                  U Vs/ s H  nUU;  d  M  SR!                  U5      PM     sn5      S95        [        U SS5      n[)        U[F        RH                  5      (       a  U R.                  (       a  U R.                  S   OSnU=(       a    [J        RL                  " U5      nU R                  RO                  UU RP                  US9nU(       a-  UR                  [F        RR                  " UU[T        -   5      5        SRE                  U5      nURW                  5       nU(       a  U(       a  [Y        UU5      nOU(       a  UnOUnUR[                  SS5      R]                  5       $ ! [         a    SnSn GN_f = fs  snf )z<Returns the help message with autogenerated details for arg.hidden_helpr   Nhidden_choicesstore_propertyzGOverrides the default *{0}* property value for this command invocation.)r   rP   zUse *{}* to disable.Tz)Enabled by default, use *{0}* to disable.z)Use *{0}* to enable and *{1}* to disable.r   r]   choices_helpr   zone ofz(only one value is supported)z*{name}*{depth} {desc}:)rg   descdepthz*_{metavar}_ must be {one_of}:

{choices}

r   )rQ   one_ofr,   z(_{metavar}_ must be {one_of}: {choices}.r   z*{0}*rb   )
field_namer   	flag_namer   z
+
)/r   helpcallabletextwrapdedentr   is_groupis_positionalr,   rb   AttributeErrorhasattrr   r<   r=   r   rU   r   rT   r   ra   r   StoreTrueFalseActionr   rQ   rR   rS   lenr   r   collectionsOrderedDictr   _CHOICE_OFFSETr   r   rc   format_utilNamespaceFormatGetUsageHelpTextr   IndentAsciiDoc_ARG_DETAILS_OFFSETrstripr   r   strip)r>   r   r   r   r,   r   
extra_helpprop_rQ   r   choices_iteritemsrg   r   dedented_descchoice_helpr   arg_typearg_namer   type_help_textr   stripped_helpall_helps                           r   GetArgDetailsr   1  su   c=#((3)iI/8+b,]]\\S&&GN
{{kkGS"2B7N?  g
 sxx)92>n*S"####JD!Q
}}T,.**0&, 
#))x/"))*>s*CD	
 ||s((CII
{{d3:: %	

 #{77883::q!#7#<	

 kk-SXX^^-G#~^W5g	WN+	+a	/ 1	GT	"	"MM'2';#:#:;;$%67
+JD#"//$/-077 5>12 8 +
 ..
% , 	sen456<CC		'8J D 	
 	6==		/6#/6!. &GNN1%w#  > 		
 S&$'(0==>>(+(:(:s!!!$HCk99(CJXX..8 / N 
 
/
/e&99 xx
+%%'-M/ABH!HH			&'	*	0	0	22S  gnR#s   4T/ 
UU/U Uc                     U R                   (       a  gU R                  (       a  gU R                  (       a%  U R                   H  n[	        U5      (       d  M    g   g)zHReturns True if arg is a positional or group that contains a positional.FT)r   r   r   	arguments_IsPositional)r>   as     r   r   r     s@    ]]\\]]	q		  
r   c                     U (       d  gU R                  S5      (       a  SU SS S4$ U R                  S5      (       a  SU SS 4$ U R                  S	5      (       a  S
U SS 4$ U S   R                  5       (       a  gSU 4$ )z.Arg name usage string key function for sorted.)r   r   r}   r      Nr   r[   rx   -   r   r   r   r   )r`   isalphar~   s    r   _GetArgUsageSortKeyr     s    	wd12htd12h;sd12h;Awd7Nr   c                 p   SnU R                    HF  nUR                  (       a  M  UR                  (       a  [        U5      nU(       d    gU(       a    gUnMH     U(       aV  [	        U [
        5      (       dA  UR                  U R                  :w  a'  [        R                  " U5      nU R                  Ul        U$ )z<Returns the single non-hidden arg in args.arguments or None.N)r   r   r   GetSingletonra   rD   r   copy)args	singletonr>   s      r   r   r     s    )^^c
}}
||cI  //


4#3#3
3		)$I ,,I	r   c                    [         R                  " SS[         R                  " SS[        U SSS9=(       d    S5      5      nU R                  (       a  [	        U 5      nU(       a  Un U R                  (       a*  [        U 5      (       a  gU R                  (       a  S	U4$ S
U4$ U R                  [        R                  :X  a  SU4$ U R                  (       a  gU R                  (       a  SU4$ [        U5      $ )zArg key function for sorted.z +r]   z	[](){}|[]r   FT)ro   hiddenr            rx   )rG   rH   GetArgUsager   r   r   r   rT   rV   rW   r   r   )r>   rg   r   s      r   GetArgSortKeyr     s    	
	ff["k#U4HNBO
$
 	\\S!Ic\\S
Wnd7N
yyH&&&d7N__d7N	T	""r   c                 `    [         R                  " SU 5      (       a  U $ SR                  U 5      $ )zCReturns usage enclosed in [...] if it hasn't already been enclosed.z^\[[^][]*(\[[^][]*\])*[^][]*\]$z[{}])rG   r@   rU   )r   s    r   _MarkOptionalr     s*     XX0%88L	u	r   c	           
      	   U R                   (       a  U(       d  gU R                  (       aC  [        U 5      n	U	(       a1  U	R                  (       d  U	R                  [        R
                  :w  a  U	n U R                  (       d  U R                  (       a
  [        XS9n
Ou[        U [        R                  5      (       a  [        R                  nO:U(       d#  [        U SS5      (       a  [        R                  nO[        R                  n[!        XX;US9n
U
(       a#  U(       a  U R"                  (       d  [%        U
5      n
U
$ U R&                  (       a  SOSn/ n/ n/ nUc  Sn/ nOSnU R(                  (       a  [+        U R,                  [.        S	9OU R,                  nU GH  nUR                   (       a	  U(       d  M  UR                  (       a  [        U5      n	U	(       a  U	nUR                  (       d:  UR                  [        R
                  :X  a  UR1                  [3        UX7US
95        M  [5        U5      (       a  UR1                  U5        M  [3        UX7US
9n
U
(       d  M  UR"                  (       a  X;  a  UR1                  U
5        M  M  U(       a  [%        U
5      n
X;  d  GM
  UR1                  U
5        GM     / n/ nSnSnU(       a|  SnU HR  n[3        UX8S9n
U
(       d  M  UR"                  (       d  SnU
n[%        U
5      n
U
U:w  a  US-  nUR1                  U
5        MT     U(       a  SR7                  US   SU-  5      US'   U(       a   UR1                  UR9                  U5      5        U(       at  U(       aN  U(       d&  U(       a  U(       a  U(       a  UR1                  S5        UR1                  UR9                  U5      5        OU(       a  U(       a  UR1                  S5        U(       a  U[+        U[:        S	9-   nOUU-   nU(       a'  U(       a   UR1                  SR9                  U5      5        SR9                  U5      n
U R"                  (       a  SR7                  U
5      $ U(       d  [=        U5      S:  a  [%        U
5      n
U
$ )a  Returns the argument usage string for arg or all nested groups in arg.

Mutually exclusive args names are separated by ' | ', otherwise ' '.
Required groups are enclosed in '(...)', otherwise '[...]'. Required args
in a group are separated from the optional args by ' : '.

Args:
  arg: The argument to get usage from.
  brief: bool, If True, only display one version of a flag that has multiple
    versions, and do not display the default value.
  definition: bool, Definition list usage if True.
  markdown: bool, Add markdown if True.
  optional: bool, Include optional flags if True.
  top: bool, True if args is the top level group.
  remainder_usage: [str], Append REMAINDER usage here instead of the return.
  value: bool, If true display flag name=value for non-Boolean flags.
  hidden: bool, Include hidden args if True.

Returns:
  The argument usage string for arg or all nested groups in arg.
r   )rX   inverted_synopsisF)r   rX   r   ro    | r]   Tkey)rX   ro   r   r   )rX   r   r   z{}{}rm   r_   r   z[optional flags]z({}))r   r   r   rT   rV   rW   r   rY   ra   r   r   rv   r{   r   rz   ry   r   r   r   is_mutex	sort_argsr   r   r   r   r   r   rU   r   r   r   )r>   r   
definitionrX   optionaltopremainder_usagero   r   r   r   r   seppositional_argsrequired_usageoptional_usageinclude_remainder_usager   r   positional_usageall_other_usagenestingoptional_positionals
usage_orig	all_usages                            r   r   r     s   @ 	]]6\\S!Iioo1C1CCc	
 8e	C99	:	: %%gc+>FF"++("))(
Xe S__E"eL 3#/.."O# 
 S]].== 
 a{{6zzq/i	::!''X%7%77
a(
G 
q		Q!hFKe	
&



& ' &%&



&1 2 /'G!h>e]]#
e$J
Q,'e$  #]]+;B+?wOr388N34
"6.s#SXXn56	3/0
 60$ I !?2I0SXXo./
((9
%__==	Y!#% E	,r   c                    ^^^ [        5       mT(       a  TR                  S5        SUUU4S jjmT" U 5        [        T[        S9$ )zReturns the list of all flags in arg.

Args:
  arg: The argument to get flags from.
  optional: Do not include required flags if True.

Returns:
  The list of all/optional flags in arg.
--helpc                   > U R                   (       a  gU R                  (       a8  U(       a  U(       a  U R                  nU R                   H  n T" XS-   US9  M     g[	        U SS5      nU(       a  Un U R
                  (       al  U R                  (       dZ  U R                  (       dH  T(       a  U(       a  U R                  (       d(  TR                  [        U R
                  5      S   5        ggggg)z%GetFlags() helper that adds to flags.Nr   )levelr   show_invertedr   )
r   r   r   r   r   r   r   	is_globaladdr   )r>   r	  r   r
  _GetFlagsHelperflagsr   s       r   r  !GetFlags.<locals>._GetFlagsHelper  s    
}}
||	8??#19x@  c?D9m	 

##--83??		&++,Q/0 4C   $ r   r   )r   T)setr  r   r   )r>   r   r  r  s    `@@r   GetFlagsr    s=     %%	IIh1 10 #	.	//r   c                       \ rS rSrSrS rSrg)Sectioni  zA positional/flag section.

Attribute:
  heading: str, The section heading.
  args: [Argument], The sorted list of args in the section.
c                     Xl         X l        g r)   )headingr   )r   r  r   s      r   r   Section.__init__  s    LIr   )r   r  Nr   r$   r   r   r  r    s    r   r  c                    ^^^ [         R                  " 5       m[        5       n[        5       nU(       d
  U(       a  S1nU  GHz  nUR                  (       a  M  [	        U5      (       a#  SnUT;  a  / TU'   TU   R                  U5        MJ  UR                  (       a  U(       d  UR                  (       a  UR                  OU/ Hj  nUR                  (       d  M  UR                  (       a  M)  UR                  S   n	U(       a  MA  U	R                  S5      (       d  MY  UR                  U	5        Ml     M  UR                  (       a  SnO[        USS5      =(       d    Sn[        US	5      (       a.  UR                  U;   a  GM@  UR                  UR                  5        UT;  a  / TU'   TU   R                  U5        GM}     / n
U(       a  S
mO[         R"                  mU(       a*  SSTS/n[%        T Vs/ s H  oU;  d  M
  UPM     sn5      mOSST/nT Vs/ s H  oU;  d  M
  UPM     snmUUU4S jnUT-    H7  nUT;  a  M  U
R                  ['        U" U5      [)        TU   US95      5        M9     X4$ s  snf s  snf )a  Returns the positional/flag sections in document order.

Args:
  arguments: [Flag|Positional], The list of arguments for this command or
    group.
  is_root: bool, True if arguments are for the CLI root command.
  is_group: bool, True if arguments are for a command group.
  sort_top_level_args: bool, True if top level arguments should be sorted.

Returns:
  ([Section] global_flags)
    global_flags - The sorted list of global flags if command is not the root.
r  zPOSITIONAL ARGUMENTSr   r[   REQUIREDcategoryNOTHERrR   GLOBALc                    > U S:X  a9  [        T5      [        S/5      -
  (       a  SnU$ TT;   a  SnU$ ST;   a  SnU$ SnU$ SU ;   d  SU ;   a  U $ U S-   $ )z4Returns the arg section heading for an arg category.r  FLAGSzOTHER FLAGSr  zOPTIONAL FLAGS	ARGUMENTSz FLAGS)r  )r  other_flags_heading
categoriescommonremaining_categoriess     r   _GetArgHeading&GetArgSections.<locals>._GetArgHeading  s    7 
!	"S'^	3% !  Z+
 ! 	 #. !  &  h'X"5ohr   )r   r   )r   r   r  r   r   r   r  r   r   r   r`   r  r   r   r   rR   r   COMMONLY_USED_FLAGSr   r  rD   )r   is_rootr   sort_top_level_argsdestsglobal_flagsr>   r  r   rf   sectionsinitial_categoriesr?   r#  r   r!  r"  s                 @@@r   GetArgSectionsr,    s=    &&(*
%%,	X:Lc
}}S'h		#!
8!!#&
}}W #s}}3%7!AKKK!!!$$dood33T"	 8
 
hj$/:7hsF	U	iiz!jx$5 F (F%%F0*fgN!>Jq+="=J> 1*fEa*<!<:$ %';;hz!OO8$$X.:M	
 < 
	M 	?s   1	I6>I6	I;"I;c                   ^^ U4S jmU4S jnSU-  S-  R                  [        R                  " SX2-
  S9R                  UR	                  SS5      5      5      R	                  S	S
5      n[        U 5      U[        U5      -
  S-
  :  a%  U" U< U < 35        T" SU-  S-  5        U" U5        gT" U< U < 35        U" SU[        U 5      -
  [        U5      -
  S-
  -  SU4-  5        g)a  Helper function that does two-column writing.

If the first column is too long, the second column begins on the next line.

Args:
  prefix: str, Text for the first column.
  message: str, Text for the second column.
  indent: int, Width of the first column.
  length: int, Width of both columns, added together.
  spacing: str, Space to put on the front of prefix.
  writer: file-like, Receiver of the written output.
c                 (   > TR                  U 5        g r)   )write)swriters    r   WWrapWithPrefix.<locals>.WD  s    
LLOr   c                    > T" U S-   5        g )Nr   r$   )r0  r2  s    r   WlnWrapWithPrefix.<locals>.WlnG  s    a$hKr   z
%%%dsr]   F)break_on_hyphenswidthr   z&| z&|z |rx   z%%%dsz	%%%ds %%sr   N)r   r   TextWrapperwrapr   r   )prefixmessageindentlengthspacingr1  r5  r2  s        ` @r   WrapWithPrefixr@  6  s     6Ct


$FOD./
 wtT 
 	[6CL(1,, '6"#gL
  !vF+c'l:Q>?3.Pr   c           	        ^  T R                  5         SR                  T R                  5       5      n[        T R                  5       5      S:  =(       a    T R                  5       S   S:H  nU(       a  SOSn[        R
                  " 5       nUR                  S5        / nU(       d  UR                  [        USSSS	95        T R                  5       nT R                  5       n[        U 4S
 j[        R                  " U5       5       5      n	[        U 4S j[        R                  " U5       5       5      n
/ nU	(       a  UR                  S5        U
(       a  UR                  U5        U	(       d  U
(       a&  UR                  SSR                  U5      -  5        SnO
[        USS9nSR                  U5      nSR                  US9nUR                  X-   S-   5        U	(       a%  [!        SSR                  U	5      ["        [$        SUS9  U
(       a(  [!        SU-  SR                  U
5      ["        [$        SUS9  U(       a%  [!        SSR                  U5      ["        [$        SUS9  UR                  S['        T 5      -   5        UR)                  5       $ )a#  Return the command Usage string.

Args:
  command: calliope._CommandCommon, The command object that we're helping.
  argument_interceptor: parser_arguments.ArgumentInterceptor, the object that
    tracks all of the flags for this command or group.

Returns:
  str, The command usage string.
r]   rx   r   topiccommandzUsage: TF)r   r   r   c              3   |   >#    U  H1  u  pTR                  5       (       d  UR                  (       a  M-  Uv   M3     g 7fr)   IsHiddenr   .0rg   	help_inforC  s      r   	<genexpr>GetUsage.<locals>.<genexpr>  s4      9
4					9#6#6 d9   ,<	<c              3   |   >#    U  H1  u  pTR                  5       (       d  UR                  (       a  M-  Uv   M3     g 7fr)   rE  rG  s      r   rJ  rK    s4      ;
4					9#6#6 d;rL  groupz<%s>r   N)r   z
{command} rC  r   zgroup may bez  )r?  r1  z	%s may bezoptional flags may be)LoadAllSubElementsr   GetPathr   ioStringIOr/  r   r   GetSubGroupHelpsGetSubCommandHelpsr   r<   r   r  rU   r@  HELP_INDENT
LINE_WIDTHGetHelpHintgetvalue)rC  argument_interceptorcommand_pathrB  
command_idbufusage_partsgroup_helpscommand_helpsgroupscommandsall_subtypesoptional_flags	usage_msg
non_options   `              r   GetUsagerg  g  s'    
'//+,,
goo
 A
%
I'//*;A*>'*I%wY*
#))I+	(u$O ((*+,,.- "}}[9 &
  "}}]; ( , 
#xv

< 889N2TBNhh{#)""<"8*))J"T)*

6 j 

8 

>" ))D;w''(	r   c                    ^ ^^ SmSmU 4S jnUU4S jnU" U5      (       d  g[         R                  " 5       nTU;   a	  U" XAT5        TU;   a	  U" XAT5        UR                  5       $ )a  Constructs an alternative Usage markdown string organized into categories.

The string is formatted as a series of tables; first, there's a table for
each category of subgroups, next, there's a table for each category of
subcommands. Each table element is printed under the category defined in the
surface definition of the command or group with a short summary describing its
functionality. In either set of tables (groups or commands), if there are no
categories to display, there will be only be one table listing elements
lexicographically. If both the sets of tables (groups and commands) have no
categories to display, then an empty string is returned.

Args:
  command: calliope._CommandCommon, The command object that we're helping.
  categories: A dictionary mapping category name to the set of elements
    belonging to that category.

Returns:
  str, The command usage markdown string organized into categories.
rC  command_groupc           
      d  > Sn[        X   5      S:X  a  [        R                  X   ;   a  SnU R                  S5        U R                  SR	                  SR                  UR                  S5      5      SR                  TR                  5       5      S95        [        [        R                  " X   5      5       H  u  pEU(       d  U R                  S	R	                  US
95        U R                  S5        [        US S9 H  nSnUR                  S:X  a  UR                  SS nOLUR                  S:X  a  UR                  SS nO,UR                  S:X  a  UR                  SS nOUR                  nU R                  SR	                  UR                  R                  SS5      US95        M     M     g)z=Writes the markdown string to the buffer passed by reference.Fr   Tr   z!# Available {type}s for {group}:
r]   r   )rb   rN  z
### {category}

)r  ---------------------- | ---
c                     U R                   $ r)   r~   es    r   <lambda>JGetCategoricalUsage.<locals>._WriteTypeUsageTextToBuffer.<locals>.<lambda>  s    AFFr   r   Nalpha
   beta	   preview   {name} | {description}
r   rg   description)r   r   UNCATEGORIZED_CATEGORYr/  rU   r   splitrQ  r   r<   r   rg   
short_helpr   )	r]  r   key_namesingle_category_is_otherr  elementselementr|  rC  s	           r   _WriteTypeUsageTextToBuffer8GetCategoricalUsage.<locals>._WriteTypeUsageTextToBuffer  s   $J !Q&'':+??!%IIfII,33(..-.((7??,- 	4 	
 %S]]:3G%HI%		(///BC	ii01H*:;'
<<7"))"#.*\\V#))!"-*\\Y&))"#.*))*		&--\\))#s3 . 	
 <	 Jr   c                 &  > U T   R                  5       (       d  U T   R                  5       (       d  g[        [        U T   R                  5       5      [        U T   R                  5       5      -   5      [        [        R                  /5      :X  a  gg)zQEnsures the categorization has real categories and is not just all Uncategorized.FT)keysr  r   r   rz  )r   command_group_keycommand_keys    r   _ShouldCategorize.GetCategoricalUsage.<locals>._ShouldCategorize  s     {#((**,-2244
Z$))+,
z+,113
4	5 
d))*	+, r   r   )rR  rS  rY  )rC  r   r  r  r]  r  r  s   `    @@r   GetCategoricalUsager    sg    * +%!
F 
:	&	&
#*$1BCJ=	r   c           	      v   UR                  SR                  USR                  U R                  5       5      S95        UR                  S5        [	        US S9 H]  nUR                  5       (       a  M  UR                  SR                  UR                  R                  SS	5      UR                  S
95        M_     g)aD  Helper method to GetUncategorizedUsage().

The elements are written to a markdown table with a special heading. Element
names are printed in the first column, and help snippet text is printed in the
second. No categorization is performed.

Args:
  command: calliope._CommandCommon, The command object that we're helping.
  elements: an iterable over backend.CommandCommon, The sub-elements that
    we're printing to the table.
  element_type: str, The type of elements we are dealing with. Usually
    'groups' or 'commands'.
  writer: file-like, Receiver of the written output.
z(# Available {element_type} for {group}:
r]   )element_typerN  rk  c                     U R                   $ r)   r~   rm  s    r   ro  *_WriteUncategorizedTable.<locals>.<lambda>+  s    r   r   rw  r   r   rx  N)	r/  rU   r   rQ  r   rF  rg   r   r|  )rC  r  r  r1  r  s        r   _WriteUncategorizedTabler    s     	,,188#388GOO4E+F 9 
 	,,/0&67g
LL"))%%c3/W=O=O 	* 	
 8r   c                 F   [         R                  " 5       nU R                  (       a%  [        X R                  R	                  5       SU5        U R
                  (       a6  UR                  S5        [        X R
                  R	                  5       SU5        UR                  5       $ )a  Constructs a Usage markdown string for uncategorized command groups.

The string is formatted as two tables, one for the subgroups and one for the
subcommands. Each sub-element is printed in its corresponding table together
with a short summary describing its functionality.

Args:
  command: calliope._CommandCommon, the command object that we're helping.

Returns:
  str, The command Usage markdown string as described above.
ra  r   rb  )rR  rS  ra  r  valuesrb  r/  rY  )rC  r]  s     r   GetUncategorizedUsager  5  so     	#^^Wnn&;&;&=xMIIdO!!((*J 
r   c                 Z    SR                  SR                  U R                  5       5      S9$ )NzUFor detailed information on this command and its flags, run:
  {command_path} --help
r]   )r[  )rU   r   rQ  rO  s    r   rX  rX  O  s*    
 F!23F45r   c                    U (       a  U R                  5       nU Vs/ s H  o"R                  5       PM     nn UR                  S5      nSR                  USU 5      nSR                  XS-   S 5      n[        R
                  " U5      R                  5       nU(       d%  SR                  UWS-   S 5      R                  5       nXW=(       d    U4$ gs  snf ! [         a$    SR                  U5      R                  5       nSn Nkf = f)a~  Extracts short help and long help from a docstring.

If the docstring contains a blank line (i.e., a line consisting of zero or
more spaces), everything before the first blank line is taken as the short
help string and everything after it is taken as the long help string. The
short help is flowing text with no line breaks, while the long help may
consist of multiple lines, each line beginning with an amount of whitespace
determined by dedenting the docstring.

If the docstring does not contain a blank line, the sequence of words in the
docstring is used as both the short help and the long help.

Corner cases: If the first line of the docstring is empty, everything
following it forms the long help, and the sequence of words of in the long
help (without line breaks) is used as the short help. If the short help
consists of zero or more spaces, None is used instead. If the long help
consists of zero or more spaces, the short help (which might or might not be
None) is used instead.

Args:
  docstring: The docstring from which short and long help are to be taken

Returns:
  a tuple consisting of a short help string and a long help string
r   r]   Nr   r   )r   r   )
splitlinesr   indexr   r   r   
ValueError)	docstringunstripped_doc_linesr0  stripped_doc_linesempty_line_indexr|  raw_long_help	long_helps           r   ExtractHelpStringsr  V  s    4 $//1-AB-A'')-AB+11"588./@0@ABjii 45I5K LMm//-0668i 88./?!/C/EFGMMOj/Z00 C  88./557jis   CAC +DD)F)NNF)r   )FFFTFNTF)>r"   
__future__r   r   r   rV   r   r   r9   enumrR  rG   sysr   googlecloudsdk.callioper   r   r   r	    googlecloudsdk.calliope.conceptsr
   r   r<   rW  rV  r   r   objectr   r&   ArgumentrD   rK   rY   ri   rq   rt   Enumrv   ry   r   r   r   r   r   r   r   r   r   r   r   r  r  r,  stdoutr@  rg  r  r  r  rX  r  r$   r   r   <module>r     s^    6 &  '      	 	 
  / : ( 4 @ 

 'v '"86& 86v&// 2(
DII  u}/C/C4IX:
>&z3z
 2#4 
Nb'0T
f 
d N EHJJ .bXvQh>45*r   