
    )                        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mZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlZej,                  rddl
mZ ddl
mZ dZdZd Zd Zd Z ej<                  ej>                  j@                  ej>                  jB                         G d dejD                               Z#y)z;Extensible interactive shell with auto completion and help.    )absolute_import)division)unicode_literalsN)base)cli_tree)config)
exceptions)
properties)render_document)encoding)application)bindingsz|
* auto-completion and active help for all commands
* state preservation across commands: *cd*, local/environment variables
a  
# Welcome to the gcloud interactive shell environment.

Tips:

* start by typing commands to get auto-suggestions and inline help
* use `tab`, `up-arrow`, or `down-arrow` to navigate completion dropdowns
* use `space` or `/` to accept the highlighted dropdown item
* run gcloud <alpha|beta> interactive --help for more info

Run *$ gcloud feedback* to report bugs or request new features.

c                     t         j                  j                  j                  j	                         xs d}|r|dz  }|| z  }t        j                  t        j                  d|       y)a  Appends tag to the Cloud SDK metrics environment tag.

  The metrics/environment tag is sent via the useragent. This tag is visible in
  metrics for all gcloud commands executed by the calling command.

  Args:
    tag: The string to append to the metrics/environment tag.
   .CLOUDSDK_METRICS_ENVIRONMENTN)	r
   VALUESmetricsenvironmentGetr   SetEncodedValueosenviron)tagmetrics_environments     lib/surface/interactive.py_AppendMetricsEnvironmentr   ?   s]     #))11==AACIr3
2::'E.0    c                  <   t         j                  ryg } t        j                         j                  D ]X  }|j	                  d      }|s| j                  dj                  |j                  d                   | j                  |       Z dj                  |       S )z0Returns the function key bindings help markdown.r   T)markdownz
{}:::
)	sixPY2r   KeyBindingsGetHelpappendformatGetLabeljoin)lineskey	help_texts      r   _GetKeyBindingsHelpr-   P   s|    WW
%!!#,,cT*Ill9##CLL$L$?@All9	 -
 
5	r   c                  H   g } t        t        j                  j                  d       D ]  }|j                  s| j                  dj                  |j                               | j                  |j                         |j                  }|dt        |t        j                        rdj                  |      }n8|dv r#t        j                  |      j                         }dj                  |      }| j                  dj                  |              dj                  |       S )	z%Returns the properties help markdown.c                     | j                   S )N)name)ps    r   <lambda>z$_GetPropertiesHelp.<locals>.<lambda>`   s    !&&r   )r+   z
*{}*::z"{}")FTz*{}*zThe default value is {}.r!   )sortedr
   r   interactiver,   r&   r'   r0   default
isinstancer"   string_types	text_typelowerr)   )r*   propr5   s      r   _GetPropertiesHelpr;   ]   s    
%Z&&228HId~~ll:$$TYY/0ll4>>"g		gs//0MM'*'%mmG,224GMM'*'/66w?@ J 
5	r   c                   2    e Zd ZdZeeedZed        Z	d Z
y)Interactivea  Start the gcloud interactive shell.

  *{command}* provides an enhanced *bash*(1) command line with features that
  include:
  {features}

  ### Display

  The *{command}* display window is divided into sections, described here
  from top to bottom.

  *Previous Output*::

  Command output scrolls above the command input section as commands are
  executed.

  *Command Input*::

  Commands are typed, completed, and edited in this section. The default prompt
  is "$ ". If a context has been set, then its tokens are prepopulated before
  the cursor.

  *Active Help*::

  As you type, this section displays in-line help summaries for commands, flags,
  and arguments. You can toggle active help on and off via the *F2* key.
  Hit *F8* to display the help text in your browser.

  *Status Display*::

  Current *gcloud* project and account information, and function key
  descriptions and settings are displayed in this section. Function keys
  toggle mode/state settings or run specific actions.
  {bindings}

  ### Auto and Tab Completion

  Command completions are displayed in a scrolling pop-up menu. Use `tab` and
  up/down keys to navigate the completions, and `space` or `/` to select the
  highlighted completion.

  Completions for _known_ commands, flags, and static flag values are displayed
  automatically. Positional and dynamic flag value completions for known
  commands are displayed after `tab` is entered. Known commands include
  `gcloud`, `bq`, `gsutil`, `kubectl`, and any command with a man page that has
  been executed at least once in any *interactive* session.

  `tab` completion for unknown commands defers to *bash*(1), while still using
  the *interactive* user interface. Absent specific command information, a
  file/path completer is used when `tab` is entered for unknown positionals
  (arguments that do not start with '-'). The default completer handles '~' path
  notation and embedded _$var_ references, but does not expand their values in
  completions.

  Configure bash completions as you normally would. *{command}* starts up bash
  in a mode that sources *~/.bashrc* with the environment variable
  *COSHELL_VERSION* set to a non-empty version value.

  Command completion resets with each simple command in the command line. Simple
  commands are separated by '|', ';', '&' and may appear after '$(', '(', '{',
  '!', *if*, *then*, *elif*, *while*, and _name_=_value_ per command exports.
  Use `tab` on an empty line to enable command executable search on PATH for
  the first token in each simple command.

  Currently simple and compound commands must be entered in a single line.

  Refer to
  [Using gcloud interactive](https://cloud.google.com/sdk/docs/interactive-gcloud)
  for more information and animated GIFs.

  ### Control Characters

  Control characters affect the currently running command or the current
  command line being entered at the prompt.

  *ctrl-c*::
  If a command is currently running, then that command is interrupted. This
  terminates the command. Otherwise, if no command is running, ctrl-c clears
  the current command line.

  *ctrl-d*::
  Exits when entered as the first character at the command prompt. You can
  also run the *exit* command at the prompt.

  *ctrl-w*::
  If a command is not currently running, then the last word on the command
  line is deleted. This is handy for "walking back" partial completions.

  ### Command history

  *{command}* maintains persistent command history across sessions.

  #### emacs mode

  *^N*:: Move ahead one line in the history.
  *^P*:: Move back one line in the history.
  *^R*:: Search backwards in the history.

  #### vi mode

  /:: Search backwards in the history.
  *j*:: Move ahead one line in the history.
  *k*:: Move back one line in the history.
  *n*:: Search backwards for the next match.
  *N*:: Search forwards for the next match.

  #### history search mode

  *ENTER/RETURN*:: Retrieve the matched command line from the history.
  *^R*:: Search backwards for the next match.
  *^S*:: Search forwards for the next match.

  ### Layout Configuration

  Parts of the layout are configurable via
  *$ gcloud config set* interactive/_property_. These properties are only
  checked at startup. You must exit and restart to see the effects of new
  settings.
  {properties}

  ### CLI Trees

  *{command}* uses CLI tree data files for typeahead, command line completion,
  and help snippet generation. A few CLI trees are installed with their
  respective Google Cloud CLI components: *gcloud* (core component), *bq*,
  *gsutil*, and *kubectl*. Trees for commands that have man(1) pages are
  generated on the fly. See `$ gcloud topic cli-trees` for details.

  ## EXAMPLES

  To set the command context of *{command}* to "gcloud ", run:

      {command} --context="gcloud "

  ## NOTES

  On Windows, install *git*(1) for a *bash*(1) experience. *{command}* will
  then use the *git* (MinGW) *bash* instead of *cmd.exe*.

  Please run *$ gcloud feedback* to report bugs or request new features.
  )r   featuresr
   c                     | j                  dd       | j                  dddd d       | j                  d	ddd d
       | j                  ddd       | j                  dddd d       y )Nz	--contextzDefault command context. This is a string containing a command name, flags, and arguments. The context is prepopulated in each command line. You can inline edit any part of the context, or ctrl-c to eliminate it.)helpz--debugT
store_truezEnable debugging display.)hiddenactionr5   r@   z--hiddenz/Enable completion of hidden commands and flags.z--promptzThe interactive shell prompt.)rB   r@   z	--suggestz_Enable auto suggestion from history. The defaults are currently too rudimentary for prime time.)add_argument)parsers    r   ArgszInteractive.Args  s    
4  6 (  * >  @ ,  . 0  2r   c                     t         j                  rt        j                  d      t	        j
                         j                  }|r"t        j                  | j                  dd       |j                  s-t        j                  t        j                  t                     t!        j"                  |j$                  |j&                  |j(                  |j*                  |j,                        }t/        d       t1        j2                  ||       y )NzCThis command does not support Python 2. Please upgrade to Python 3.F)cliforceverbose)fin)contextdebugrB   promptsuggestinteractive_shell)argsr   )r"   r#   r	   Errorgcloud_configPathssdk_rootr   Load_cli_do_not_use_directlyquietr   RenderDocumentioStringIO_SPLASHconfigurationConfigrL   rM   rB   rN   rO   r   r   main)selfrQ   rU   r   s       r   RunzInteractive.Run'  s    
ww 4 5 5 ""$--Hmm55UER::$$W)=>!!jj{{{{F 12$v.r   N)__name__
__module____qualname____doc__r-   	_FEATURESr;   detailed_helpstaticmethodrF   ra    r   r   r=   r=   p   s4    L^ &&- 2 2>/r   r=   )$re   
__future__r   r   r   rZ   r   googlecloudsdk.callioper   r   &googlecloudsdk.command_lib.interactiver   r]   googlecloudsdk.corerS   r	   r
   &googlecloudsdk.core.document_renderersr   googlecloudsdk.core.utilr   r"   PY3r   r   rf   r\   r   r-   r;   ReleaseTracksReleaseTrackALPHABETACommandr=   ri   r   r   <module>rv      s     B &  ' 	 	 ( , J 7 * * B - 
 77@=	
0"
& D%%++T->->-C-CDI/$,, I/ EI/r   