o
    X                     @   s  d 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
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mZ dd	lmZ dd
lmZ ddlZdZdZdZdZG dd deZG dd deZG dd dejZdd Z dMddZ!dNddZ"dd Z#dd Z$G d d! d!e	j%Z&dde&j'd"fd#d$Z(d%d& Z)d'd( Z*d)d* Z+dOd+d,Z,d-d. Z-d/d0 Z.d1d2 Z/d3d4 Z0d5d6 Z1				"			"	dPd7d8Z2dMd9d:Z3G d;d< d<eZ4d=d> Z5ej6fd?d@Z7dAdB Z8dCdD Z9dEdF Z:dGdH Z;dIdJ Z<dKdL Z=dS )Qz/Generate usage text for displaying to the user.    )absolute_import)division)unicode_literalsN)arg_parsers)arg_parsers_usage_text)base)parser_arguments)utilP            c                   @      e Zd ZdZdd ZdS )HelpInfozCA class to hold some the information we need to generate help text.c                 C   s   |pd| _ || _|| _dS )a
  Create 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    r   ?/tmp/google-cloud-sdk/lib/googlecloudsdk/calliope/usage_text.py__init__1   s   
	
zHelpInfo.__init__N__name__
__module____qualname____doc__r   r   r   r   r   r   .   s    r   c                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )TextChoiceSuggesterz%Utility to suggest mistyped commands.Nc                 C   s   i | _ |r| | d S d S N)_choices
AddChoices)r   choicesr   r   r   r   B   s   zTextChoiceSuggester.__init__c                 C   s"   |D ]}|| j vr|| j |< qdS )ziAdd a set of valid things that can be suggested.

    Args:
      choices: [str], The valid choices.
    Nr   )r   r!   choicer   r   r   r    J   s
   

zTextChoiceSuggester.AddChoicesc                 C   s"   |D ]}|| j vr|| j |< qdS )a  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aliasr   r   r   
AddAliasesV   s
   

zTextChoiceSuggester.AddAliasesc                    sd   | j sdS t| dd | j D d  r' fdd| j D d }| j | S  r0| j  d  S dS )zFind the item that is closest to what was attempted.

    Args:
      arg: str, The argument provided.

    Returns:
      str, The closest match.
    Nc                 S   s   g | ]}t |qS r   six	text_type.0cr   r   r   
<listcomp>r   s    z5TextChoiceSuggester.GetSuggestion.<locals>.<listcomp>r   c                    s"   g | ]}t | d  kr|qS r   r(   r+   matchr   r   r.   u   s   " r   )r   difflibget_close_matcheslower)r   argr#   r   r0   r   GetSuggestione   s   	
z!TextChoiceSuggester.GetSuggestionr   )r   r   r   r   r   r    r'   r6   r   r   r   r   r   ?   s    
r   c                   @   s   e Zd ZdS )ArgumentWrapperN)r   r   r   r   r   r   r   r7   z   s    r7   c                 C   s   t dtjd tj | S )Nz(\b[a-zA-Z][-a-zA-Z_0-9]*)z\1)resubr   MARKDOWN_ITALIC)msgr   r   r   _ApplyMarkdownItalic~   s
   r<   Fc                 C   sz   | j p| j }|rt|}| jdkrdj|dS | jdkr$dj|dS | jtjkr0dj|dS | jdkr;dj|dS |S )	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upperr<   nargsformatargparse	REMAINDER)r5   markdownr>   r   r   r   GetPositionalUsage   s   



rI   c                 C   s   |du r| j p| j }|r|drdnd}t| jtjr*| jt	| j |p)|}|dkr0dS |r6t
|}|dkr@|| }d}| jdv rMd| d }d}|| S )	z-Returns a usage-separator + metavar for flag.N--= r   )r@   r?   [])rA   rB   rC   
startswith
isinstancetyper   ArgTypeUsageGetUsageMetavarboolr<   rD   )flagrA   namerH   	separatorr   r   r   _GetFlagMetavar   s    
rX   c                 C   s2   t | }|drd| vrd|dd  d }|S )z0Returns value quoted, with preference for "...".'"r   )reprrO   )valuequotedr   r   r   _QuoteValue   s   r_   c                 C   s   | S )zMockable flag name list filter.r   )namesr   r   r   _FilterFlagNames   s   ra   c                   @   s   e Zd ZdZdZdZdS )InvertedValuer   r      N)r   r   r   NORMALINVERTEDBOTHr   r   r   r   rb      s    rb   Tc              	   C   s  |t ju rdd t| jD }n|t ju r dd t| jD }nt| j}t|}| jp0| j }|r5|r^z|d }W n t	yF   d}Y nw |rN| j
dkrP|S t| ||d}dj||dS | j
dkrx|rqd	d
d |D }	|	S d	|}	|	S g }
|D ] }t| |||d}|
dj|rtjnd||rtjnd|d q|d	|
}	| jrt| dt| ddst| jtrd| j}nt| jtrddd tt| jD }n| j}t|}|rtdtj tj tj d|rd|}|	d|7 }	|	S )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.
  c                 S      g | ]	}| d ddqS )rJ   z--[no-]r   replacer,   xr   r   r   r.          z GetFlagUsage.<locals>.<listcomp>c                 S   rg   )rJ   --no-r   rh   rj   r   r   r   r.      rl   r   r   rV   z{flag}{metavar})rU   rA   , c                 S   s   g | ]
}t j| t j qS r   )r   MARKDOWN_BOLDrj   r   r   r   r.      s    )rV   rH   z{bb}{flag}{be}{flag_metavar})bbrU   beflag_metavaris_requiredrequiredF,c                 S   s   g | ]
\}}d  ||qS )z{0}={1}rE   )r,   kvr   r   r   r.     s    
rM   rN   z```{}```z; default={0})rb   rf   sortedoption_stringsre   ra   rA   rB   rC   
IndexErrorrD   rX   rE   joinappendr   rp   defaultgetattrrP   listdictr)   	iteritemsr_   r8   searchr:   MARKDOWN_CODE)r5   briefrH   invertedr]   r`   rA   long_stringrs   usage
usage_listrV   r   default_textr   r   r   GetFlagUsage   sn   



%
!



r   c                 C   s   | j d dddS )z(Returns the inverted flag name for flag.r   rJ   rm   r   )r{   ri   )rU   r   r   r   _GetInvertedFlagName  s   r   c                 C   s   | r|  dr	| S | d S )N.)endswith)help_messager   r   r   
_Punctuate  s   r   c                 C   sl   | |v r|S |  d }r| |d  dkr|  d| dS |  ddkr-t|  d| S t|  d| S )z-Appends extra_help_message into help_message.
r   rL   

r   )rfindr   )r   extra_help_messagenewline_indexr   r   r   _AppendExtraHelp  s   r   c              
      s(  t | d| j}t|r| }|rt|nd}| jr|S | js"| jr'd}d n(| jr4| j}t | dg  nz| j	j}W n t
yG   d}d Y nw t | j	dg  g }t| dr~| j\}}}t||vr}|d| |jr}| jdv r}|dt|  n.| js| js| jrn$| jd	u r|d
t|  nt| tjr|d| jd t|  |r7| jp| j }|dkr7t | d|}t|t  dkrd}	nd}	t|tr"t|}
t|tjst |
}
g }|
D ]\}}| v rqt|}dj||d|t!  d}|| q|d|t!   |dj||	d"|d n|dj||	d" fdd|D d t | dd}t|t#j$ro| jrM| jd nd}|oVt%&|}| j	j'|| j(|d}|ro|t#)||t*  d"|}|+ }|r|rt,||}n|r|}n|}|-dd. S ) 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   r@   zUse *{}* to disable.Tz)Enabled by default, use *{0}* to disable.z)Use *{0}* to enable and *{1}* to disable.r   rL   choices_helpr   zone ofz(only one value is supported)z*{name}*{depth} {desc}:)rV   descdepthz*_{metavar}_ must be {one_of}:

{choices}

r   )rA   one_ofr!   z(_{metavar}_ must be {one_of}: {choices}.ro   c                    s   g | ]}| vrd  |qS )z*{0}*rw   rj   r   r   r   r.     s
    z!GetArgDetails.<locals>.<listcomp>rQ   )
field_nameru   	flag_namer   z
+
)/r   helpcallabletextwrapdedentr   is_groupis_positionalr!   rQ   AttributeErrorhasattrr   r)   r*   r~   rE   r   rD   r   rP   r   StoreTrueFalseActionr{   rA   rB   rC   lenr   r   collectionsOrderedDictrz   _CHOICE_OFFSETr}   r   rR   format_utilNamespaceFormatGetUsageHelpTextrt   IndentAsciiDoc_ARG_DETAILS_OFFSETrstripr   ri   strip)r5   r   r   r   r!   
extra_helpprop_rA   r   choices_iteritemsrV   r   dedented_descchoice_helparg_typearg_namer   type_help_textr   stripped_helpall_helpr   r   r   GetArgDetails1  s   






r   c                 C   s8   | j rdS | jr
dS | jr| jD ]	}t|r dS qdS )zHReturns True if arg is a positional or group that contains a positional.FT)r   r   r   	arguments_IsPositional)r5   ar   r   r   r     s   
r   c                 C   sp   | sdS |  drd| dd dfS |  drd| dd fS |  d	r,d
| dd fS | d  r4dS d| fS )z.Arg name usage string key function for sorted.)r   r   rm   r      Nrk   rJ   rc   -   r   r   r   r   )rO   isalpharn   r   r   r   _GetArgUsageSortKey  s   


r   c                 C   sn   d}| j D ]}|jrq|jrt|}|s dS |r dS |}q|r5t| ts5|j| jkr5t|}| j|_|S )z<Returns the single non-hidden arg in args.arguments or None.N)r   r   r   GetSingletonrP   r7   rt   copy)args	singletonr5   r   r   r   r     s&   

r   c                 C   s   t ddt ddt| dddpd}| jrt| }|r|} | jr2t| r'dS | jr.d	|fS d
|fS | jtj	kr<d|fS | j
rAdS | jrHd|fS t|S )zArg key function for sorted.z +rL   z	[](){}|[]r   FT)r]   hiddenr            rc   )r8   r9   GetArgUsager   r   r   rt   rD   rF   rG   r   r   )r5   rV   r   r   r   r   GetArgSortKey  s,   r   c                 C   s   t d| r| S d| S )zCReturns usage enclosed in [...] if it hasn't already been enclosed.z^\[[^][]*(\[[^][]*\])*[^][]*\]$z[{}])r8   r1   rE   )r   r   r   r   _MarkOptional  s   
r   c	              	   C   s  | j r|sdS | jrt| }	|	r|	js|	jtjkr|	} | jsW| jr(t| |d}
n"t| t	j
r2tj}n|s>t| ddr>tj}ntj}t| ||||d}
|
rU|rU| jsUt|
}
|
S | jr\dnd}g }g }g }|du rmd	}g }nd}| jryt| jtd
n| j}|D ]Y}|j r|sq~|jrt|}	|	r|	}|js|jtjkr|t||||d q~t|r|| q~t||||d}
|
sq~|jr|
|vr||
 q~|rt|
}
|
|vr||
 q~g }g }d}d}|rd}|D ]&}t|||d}
|
sq|jsd	}|
}t|
}
|
|kr|d7 }||
 q|rd|d d| |d< |r(||| |rS|rH|s?|r7|r:|r?|d ||| n|rS|rS|d |r_|t|td
 }n|| }|rq|rq|d| d|}
| jrd|
S |st|dkrt|
}
|
S )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   )rH   inverted_synopsisF)r   rH   r   r]    | rL   NTkey)rH   r]   r   r   )rH   r   r   z{}{}r[   rN   r   z[optional flags]z({}))r   r   r   rD   rF   rG   r   rI   rP   r   r   rb   rf   r   re   rd   r   rt   r   is_mutex	sort_argsrz   r   r   r~   r   r   rE   r}   r   r   )r5   r   
definitionrH   optionaltopremainder_usager]   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_usager   r   r   r     s   
 









r   c                    s:   t  r
d d fdd	  |  ttdS )	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.
  --helpr   Tc                    s   | j rdS | jr |r|r| j}| jD ]}  | |d |d qdS t| dd}|r*|} | jrF| jsH| jsJr:|r:| jsLt	| jd  dS dS dS dS dS )z%GetFlags() helper that adds to flags.Nr   )levelru   show_invertedr   )
r   r   rt   r   r   r{   r   	is_globaladdrz   )r5   r   ru   r   _GetFlagsHelperflagsr   r   r   r     s2   
z!GetFlags.<locals>._GetFlagsHelperr   N)r   T)setr   rz   r   )r5   r   r   r   r   GetFlags  s   

r   c                   @   r   )SectionzA positional/flag section.

  Attribute:
    heading: str, The section heading.
    args: [Argument], The sorted list of args in the section.
  c                 C   s   || _ || _d S r   )headingr   )r   r   r   r   r   r   r     s   
zSection.__init__Nr   r   r   r   r   r     s    r   c              	      s  t   t }t }|s|rdh}| D ]s}|jrqt|r/d}| vr'g  |<  | | q|jrX|sX|jr:|jn|gD ]}|j	rV|jsV|j	d }	|sV|	
drV||	 q=q|jr^d}nt|ddped}t|d	rw|j|v rqq||j | vrg  |<  | | qg }
|rd
ntj|rdddgtfdd D nddgfdd D  fdd} D ]}| vrq|
t||t | |d q|
|fS )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   rJ   REQUIREDcategoryNOTHERrB   GLOBALc                       g | ]}| vr|qS r   r   r+   initial_categoriesr   r   r.     s    z"GetArgSections.<locals>.<listcomp>c                    r   r   r   r+   r   r   r   r.     s    c                    sf   | dkr%t t dg rd}|S  v rd}|S d v r!d}|S d}|S d| v s-d| v r/| S | d 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_categoriesr   r   _GetArgHeading  s   z&GetArgSections.<locals>._GetArgHeading)r   r   )r   r   r   r   r   r~   r   r   r   r{   rO   r   rt   r   r   rB   r   COMMONLY_USED_FLAGSrz   r   r7   )r   is_rootr   sort_top_level_argsdestsglobal_flagsr5   r   r   rU   sectionsr  r   )r  r  r   r  r   GetArgSections  st   




	

	r  c                    s   fdd  fdd}d| d  tjd|| d|d	d
dd}t| |t| d krI|d|| f   d| d  || dS  d|| f  |d|t|  t| d  d|f  dS )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                    s     |  d S r   )writes)writerr   r   WD  s   zWrapWithPrefix.<locals>.Wc                    s    | d  d S )Nr   r   r  )r  r   r   WlnG  s   zWrapWithPrefix.<locals>.Wlnz
%%%dsrL   F)break_on_hyphenswidthr   z&| z&|z |rc   z%s%sz%%%dsz	%%%ds %%sr   N)r}   r   TextWrapperwrapri   r   )prefixmessageindentlengthspacingr  r  r   )r  r  r   WrapWithPrefix6  s&   
	"r  c                    s      d  }t  dko  d dk}|rdnd}t }|d g }|s9|t|dddd	  	 } 
 }t fd
dt|D }	t fddt|D }
g }|	rf|d |
rm|| |	sq|
r~|dd|  d}nt|dd}d|}dj|d}||| d  |	rtdd|	ttd|d |
rtd| d|
ttd|d |rtdd|ttd|d |dt   | S )a1  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.
  rL   rc   r   topiccommandzUsage: TF)r   r   r   c                 3   &    | ]\}}   s|js|V  qd S r   IsHiddenr   r,   rV   	help_infor  r   r   	<genexpr>      
zGetUsage.<locals>.<genexpr>c                 3   r  r   r   r"  r$  r   r   r%    r&  groupz<%s>r   N)r   z
{command} r$  r   zgroup may bez  )r  r  z	%s may bezoptional flags may be)LoadAllSubElementsr}   GetPathr   ioStringIOr  r~   r   GetSubGroupHelpsGetSubCommandHelpsrz   r)   r   r   rE   r  HELP_INDENT
LINE_WIDTHGetHelpHintgetvalue)r  argument_interceptorcommand_pathr  
command_idbufusage_partsgroup_helpscommand_helpsgroupscommandsall_subtypesoptional_flags	usage_msg
non_optionr   r$  r   GetUsageg  sx    



	r?  c                    sf   dd fdd}fdd}||sdS t  }|v r%||| |v r/||| | S )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.
  r  command_groupc              	      s&  d}t || dkrtj|| v rd}| d | djd|dd  d tt	
|| D ]Z\}}|sE| d	j|d
 | d t|dd dD ]=}d}|jdkrc|jdd }n|jdkrp|jdd }n|jdkr}|jdd }n|j}| dj|jdd|d qRq6dS )z=Writes the markdown string to the buffer passed by reference.Fr   Tr   z!# Available {type}s for {group}:
rL   r   )rQ   r'  z
### {category}

)r   ---------------------- | ---
c                 S      | j S r   rn   er   r   r   <lambda>      zJGetCategoricalUsage.<locals>._WriteTypeUsageTextToBuffer.<locals>.<lambda>r   Nalpha
   beta	   preview   {name} | {description}
r   rV   description)r   r   UNCATEGORIZED_CATEGORYr  rE   r}   splitr)  rz   r)   r   rV   
short_helpri   )r5  r  key_namesingle_category_is_otherr   elementselementrR  r$  r   r   _WriteTypeUsageTextToBuffer  s>   




z8GetCategoricalUsage.<locals>._WriteTypeUsageTextToBufferc                    sT   |    s|     sdS tt|    t|      ttjgkr(dS dS )zQEnsures the categorization has real categories and is not just all Uncategorized.FT)keysr   r   r   rP  )r  )command_group_keycommand_keyr   r   _ShouldCategorize  s   


z.GetCategoricalUsage.<locals>._ShouldCategorizer   )r*  r+  r1  )r  r  rW  r[  r5  r   )r  rY  rZ  r   GetCategoricalUsage  s   #r\  c                 C   sl   | dj|d|  d | d t|dd dD ]}| r#q| dj|jd	d
|jd qdS )aZ  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}:
rL   )element_typer'  rA  c                 S   rB  r   rn   rC  r   r   r   rE  +  rF  z*_WriteUncategorizedTable.<locals>.<lambda>r   rM  r   r   rN  N)	r  rE   r}   r)  rz   r!  rV   ri   rR  )r  rU  r]  r  rV  r   r   r   _WriteUncategorizedTable  s   
r^  c                 C   sN   t  }| jrt| | j d| | jr#|d t| | j d| | S )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.
  r9  r   r:  )r*  r+  r9  r^  valuesr:  r  r1  )r  r5  r   r   r   GetUncategorizedUsage5  s   
r`  c                 C   s   dj d|  dS )NzUFor detailed information on this command and its flags, run:
  {command_path} --help
rL   )r3  )rE   r}   r)  r$  r   r   r   r0  O  s   r0  c                 C   s   | rW|   }dd |D }z"|d}d|d| }d||d d }t| }W n tyA   d| }d}Y nw |sQd||d d  }||pU|fS dS )	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
  c                 S   s   g | ]}|  qS r   )r   )r,   r  r   r   r   r.   r  s    z&ExtractHelpStrings.<locals>.<listcomp>r   rL   Nr   r   )r   r   )
splitlinesindexr}   r   r   r   
ValueError)	docstringunstripped_doc_linesstripped_doc_linesempty_line_indexrR  raw_long_help	long_helpr   r   r   ExtractHelpStringsV  s    
rj  )F)NNFr/   )FFFTFNTF)>r   
__future__r   r   r   rF   r   r   r2   enumr*  r8   sysr   googlecloudsdk.callioper   r   r   r    googlecloudsdk.calliope.conceptsr	   r   r)   r/  r.  r   r   objectr   r   Argumentr7   r<   rI   rX   r_   ra   Enumrb   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   r  stdoutr  r?  r\  r^  r`  r0  rj  r   r   r   r   <module>   s~   ;



L
}
 
*g1[T