
                         l   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
Jr  SSKJr  SSKJr  SS	KJr  SSKr " S
 S\5      r " S S\R(                  " \R*                  \5      5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rSS jrS rg)zTools for launching a browser.    )absolute_import)division)unicode_literalsN)parser)log)encoding)filesc                       \ rS rSrS rSrg)FakeSubprocessModule#   c                     [         R                  " [        R                  5       nUR	                  X3S.5        [
        R                  " U40 UD6sS S S 5        $ ! , (       d  f       g = f)N)stderrstdout)r	   
FileWriterosdevnullupdate
subprocessPopen)selfargskwargsr   s       5lib/googlecloudsdk/command_lib/interactive/browser.pyr   FakeSubprocessModule.Popen%   sD    			"**	%mmw:;d-f- 
&	%	%s   *A
A' N)__name__
__module____qualname____firstlineno__r   __static_attributes__r       r   r   r   #   s    .r!   r   c                   f    \ rS rSrSrS r\R                  S 5       r\R                  S 5       r	Sr
g)CommandReferenceMapper+   z7Command to URL or man page reference mapper base class.c                     Xl         X l        g )N)clir   )r   r&   r   s      r   __init__CommandReferenceMapper.__init__.   s    HIr!   c                     g)z6Returns the man-style command for the command in args.Nr   r   s    r   GetManCommandReferenceMapper.GetMan2        r!   c                     g)z1Returns the help doc URL for the command in args.Nr   r*   s    r   GetURLCommandReferenceMapper.GetURL7   r-   r!   )r   r&   N)r   r   r   r   __doc__r'   abcabstractmethodr+   r/   r    r   r!   r   r#   r#   +   s>    ?    r!   r#   c                   $    \ rS rSrSrS rS rSrg)GcloudReferenceMapper=   zgcloud help reference mapper.c                 @    SR                  U R                  S/-   5      $ )N z--helpjoinr   r*   s    r   r+   GcloudReferenceMapper.GetMan@   s    88DII
*++r!   c                 F    SR                  S/U R                  SS  -   5      $ )N/z-https://cloud.google.com/sdk/gcloud/reference   r9   r*   s    r   r/   GcloudReferenceMapper.GetURLC   s*    88	89DIIabMIK Kr!   r   Nr   r   r   r   r1   r+   r/   r    r   r!   r   r5   r5   =   s    %,Kr!   r5   c                   $    \ rS rSrSrS rS rSrg)BqReferenceMapperH   zbq help reference mapper.c                 &    U R                   S   S-   $ )Nr   z help | less)r   r*   s    r   r+   BqReferenceMapper.GetManK   s    99Q<.((r!   c                     g)Nz6https://cloud.google.com/bigquery/bq-command-line-toolr   r*   s    r   r/   BqReferenceMapper.GetURLN   s    Cr!   r   Nr@   r   r!   r   rB   rB   H   s    !)Dr!   rB   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )GsutilReferenceMapperR   zgsutil help reference mapper.c                 r   > [         [        U ]  X5        [        U5      S:  a  US   OSU l        S/U l        g )Nr>    z,https://cloud.google.com/storage/docs/gsutil)superrI   r'   len
subcommandrefr   r&   r   	__class__s      r   r'   GsutilReferenceMapper.__init__U   s4    	
/:!$TQd1gBDO>?DHr!   c                     S/nU R                   (       a  UR                  U R                   5        UR                  S5        SR                  U5      $ )Nzgsutil help| lessr8   rO   appendr:   r   cmds     r   r+   GsutilReferenceMapper.GetManZ   s:    /C	jj!JJx88C=r!   c                     U R                   (       a@  U R                  R                  S5        U R                  R                  U R                   5        SR                  U R                  5      $ )Ncommandsr=   rO   rP   rW   r:   r*   s    r   r/   GsutilReferenceMapper.GetURLa   s@    
hhooj!
hhoodoo&88DHHr!   rP   rO   
r   r   r   r   r1   r'   r+   r/   r    __classcell__rR   s   @r   rI   rI   R   s    %@
 r!   rI   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )KubectlReferenceMapperh   zkubectl help reference mapper.c                 T  > [         [        U ]  X5        [        U5      S:  a  US   OSU l         UR
                  [        R                     US      [        R                     nSR                  UR                  S5      SS 5      nSU/U l        g ! [        [        4 a    Sn Nf = f)Nr>   rL   r   .   zv1.8z-https://kubernetes.io/docs/user-guide/kubectl)rM   rd   r'   rN   rO   rootr   LOOKUP_COMMANDSLOOKUP_CLI_VERSIONr:   split
IndexErrorKeyErrorrP   )r   r&   r   full_versionversionrR   s        r   r'   KubectlReferenceMapper.__init__k   s    	
 $0;!$TQd1gBDOhhv556tAw?002l++C0156g @IDH ! gs   AB B'&B'c                     S/nU R                   (       a  UR                  U R                   5        UR                  S5        SR                  U5      $ )Nzkubectl helprU   r8   rV   rX   s     r   r+   KubectlReferenceMapper.GetManv   s;    
C	jj!JJx88C=r!   c                     U R                   (       a(  U R                  R                  SU R                   -   5        SR                  U R                  5      $ )N#r=   r]   r*   s    r   r/   KubectlReferenceMapper.GetURL}   s5    
hhoocDOO+,88DHHr!   r_   r`   rb   s   @r   rd   rd   h   s    &	J r!   rd   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )UnknownReferenceMapper   z&Unkmown command help reference mapper.c                 h   > [         [        U ]  X5        [        R                  " US   5      U l        g )Nr   )rM   rx   r'   r	   FindExecutableOnPathknownrQ   s      r   r'   UnknownReferenceMapper.__init__   s)    	
 $0;++DG4DJr!   c                 J    U R                   (       d  g SU R                  S   -   $ )Nzman r   )r|   r   r*   s    r   r+   UnknownReferenceMapper.GetMan   s    ::DIIaL  r!   c                     U R                   (       d  g S[        R                  ;   a  SS/nOS/nUR                  U R                  S   S-   5        SR                  U5      $ )Ndarwinz8https://developer.apple.com/legacy/library/documentationzDarwin/Reference/ManPages/man1z$http://man7.org/linux/man-pages/man1r   z.1.htmlr=   )r|   sysplatformrW   r   r:   )r   rP   s     r   r/   UnknownReferenceMapper.GetURL   sV    ::3<<G-/c 44cJJtyy|i'(88C=r!   )r|   r`   rb   s   @r   rx   rx      s    .5!
	 	r!   rx   c                    [         [        [        [        S.nUc  [	        U5      n/ nU R
                  R                  U5       H  nUR                  U:  d  M  U(       ar  UR                  R                  [
        R                  5      (       dD  UR                  [
        R                  R                  [
        R                  R                  4;   d  M  UR                  UR                   5        M     U(       d  U(       a  g/ SQnUR                  US   ["        5      nU" X5      nU(       a  UR%                  5       $ UR'                  5       $ )aO  Determine the reference url of the command/group preceding the pos.

Args:
  cli: the prompt CLI object
  line: a string with the current string directly from the shell.
  pos: the position of the cursor on the line.
  man_page: Return help/man page command line if True.

Returns:
  A string containing the URL of the reference page.
)bqgcloudgsutilkubectlN)r   alphainteractiver   )rB   r5   rI   rd   rN   r   ParseCommandstarttreegetrj   
token_typeArgTokenTypeCOMMANDGROUPrW   valuerx   r+   r/   )	r&   lineposman_pagemappersr   argmapper_classmappers	            r   _GetReferenceURLr      s     %%'	' 	[
d)C	$ZZ$$T*c
yy3V++,,6..66!..446 	6
kk#)) + 
-DT!W&<=,"&$9&--/9r!   c                   ^ [        [        R                  " [        R                  S5      5      n[        XX#5      nU(       d  gU(       a  U R                  USS9  g[        5       [        l	         [        R                  " 5       nUR                  U5        g! [        R                   a  mU R                  U4S j5         Sm@gSm@ff = f)z;Opens a web browser or local help/man page for line at pos.
SSH_CLIENTNT)alternate_screenc                  2   > [         R                  " ST 5      $ )Nzfailed to open browser: %s)r   error)es   r   <lambda>#OpenReferencePage.<locals>.<lambda>   s    		6:r!   )boolr   GetEncodedValuer   environr   Runr   
webbrowserr   r   open_new_tabErrorrun_in_terminal)r&   r   r   r   rP   browserr   s         @r   OpenReferencePager      s    (**2::|DE(C2#	
GGC$G'
.0*<nnG			 <:< <<s   0&B C
+CC
)NF)r1   
__future__r   r   r   r2   r   r   r   r   &googlecloudsdk.command_lib.interactiver   googlecloudsdk.corer   googlecloudsdk.core.utilr   r	   sixobjectr   with_metaclassABCMetar#   r5   rB   rI   rd   rx   r   r   r   r!   r   <module>r      s     % &  ' 
 	  
  9 # - * 
.6 .S//VD $K2 KD. D2 ,3 63 0$:N<r!   