
x6[c           @   s,  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 m	 Z	 m
 Z
 d d l m Z y d  d l m Z Wn e k
 r d  d l Z n Xd Z d	 Z d
 Z e j d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d S(   iNi   (   t   echo(   t   split_arg_string(   t   MultiCommandt   Optiont   Argument(   t   Choice(   t   abct   =s  
%(complete_func)s() {
    local IFS=$'
'
    COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
                   COMP_CWORD=$COMP_CWORD \
                   %(autocomplete_var)s=complete $1 ) )
    return 0
}

%(complete_func)setup() {
    local COMPLETION_OPTIONS=""
    local BASH_VERSION_ARR=(${BASH_VERSION//./ })
    # Only BASH version 4.4 and later have the nosort option.
    if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
        COMPLETION_OPTIONS="-o nosort"
    fi

    complete $COMPLETION_OPTIONS -F %(complete_func)s %(script_names)s
}

%(complete_func)setup
s9  
%(complete_func)s() {
    local -a completions
    local -a completions_with_descriptions
    local -a response
    response=("${(@f)$( env COMP_WORDS="${words[*]}" \
                        COMP_CWORD=$((CURRENT-1)) \
                        %(autocomplete_var)s="complete_zsh" \
                        %(script_names)s )}")

    for key descr in ${(kv)response}; do
      if [[ "$descr" == "_" ]]; then
          completions+=("$key")
      else
          completions_with_descriptions+=("$key":"$descr")
      fi
    done

    if [ -n "$completions_with_descriptions" ]; then
        _describe -V unsorted completions_with_descriptions -U -Q
    fi

    if [ -n "$completions" ]; then
        compadd -U -V unsorted -Q -a completions
    fi
    compstate[insert]="automenu"
}

compdef %(complete_func)s %(script_names)s
s   [^a-zA-Z0-9_]c         C   sa   t  j d |  j d d   } | d k r0 t n t } | i d | d 6|  d 6| d 6j   d	 S(
   Nt    t   -t   _t   zshs   _%s_completiont   complete_funct   script_namest   autocomplete_vart   ;(   t   _invalid_ident_char_ret   subt   replacet   COMPLETION_SCRIPT_ZSHt   COMPLETION_SCRIPT_BASHt   strip(   t	   prog_namet   complete_vart   shellt   cf_namet   script(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   get_completion_scriptK   s    c         C   s>  |  j  | | d t } | j | j } x| r9t | j t  r5| j j s | j j | |  \ } } } | d k r} | S| j  | | d | d t } | j | j } q6xk | r| j j | |  \ } } } | d k r | S| j  | | d | d t d t
 d t } | j } q W| } | j | j } q+ Pq+ W| S(   s  
    Parse into a hierarchy of contexts. Contexts are connected through the parent variable.
    :param cli: command definition
    :param prog_name: the program that is running
    :param args: full list of args
    :return: the final context/command parsed
    t   resilient_parsingt   parentt   allow_extra_argst   allow_interspersed_argsN(   t   make_contextt   Truet   protected_argst   argst
   isinstancet   commandR   t   chaint   resolve_commandt   Nonet   False(   t   cliR   R#   t   ctxt   cmd_namet   cmdt   sub_ctx(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   resolve_ctxU   s0    				c         C   s   |  o |  d  d k S(   s   
    :param param_str: param_str to check
    :return: whether or not this is the start of an option declaration (i.e. starts "-" or "--")
    i   R	   (    (   t	   param_str(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   start_of_optionz   s    c         C   s   t  | t  s t S| j r  t Sd } xk t t g  |  D] } | t k r6 | ^ q6   D]8 \ } } | d | j k r{ Pn  t	 |  rX | } qX qX W| r | | j
 k r t St S(   sE  
    :param all_args: the full original list of args supplied
    :param cmd_param: the current command paramter
    :return: whether or not the last option declaration (i.e. starts "-" or "--") is incomplete and
    corresponds to this cmd_param. In other words whether this cmd_param option can still accept
    values
    i   N(   R$   R   R)   t   is_flagR(   t	   enumeratet   reversedt	   WORDBREAKt   nargsR1   t   optsR!   (   t   all_argst	   cmd_paramt   last_optiont   argt   indext   arg_str(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   is_incomplete_option   s    	>c         C   s   t  | t  s t S|  | j } | d k r0 t S| j d k rC t St  | t j  r} | j d k r} t	 |  | j k  r} t St S(   sL  
    :param current_params: the current params and values for this argument as already entered
    :param cmd_param: the current command parameter
    :return: whether or not the last argument is incomplete and corresponds to this cmd_param. In
    other words whether or not the this cmd_param argument can still accept values
    ii   N(
   R$   R   R)   t   nameR(   R!   R6   R   t   Iterablet   len(   t   current_paramsR9   t   current_param_values(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   is_incomplete_argument   s    $c         C   s   g  } t  | j t  rU g  | j j D]' } t |  j |  r% | d f ^ q% } nd | j d k	 r | j d |  d | d |  } g  | D]' } t  | t  r | n	 | d f ^ q } n  | S(   s  
    :param ctx: context associated with the parsed command
    :param args: full list of args
    :param incomplete: the incomplete text to autocomplete
    :param cmd_param: command definition
    :return: all the possible user-specified completions for the param
    R+   R#   t
   incompleteN(	   R$   t   typeR   t   choicest   strt
   startswithR(   t   autocompletiont   tuple(   R+   R#   RE   R9   t   resultst   ct   dynamic_completions(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   get_user_autocompletions   s    :	4c         c   sY   xR |  j  j |   D]> } | j |  r |  j  j |  |  } | j sQ | VqQ q q Wd S(   s   
    :param ctx: context associated with the parsed command
    :starts_with: string that visible commands must start with.
    :return: all visible (not hidden) commands that start with starts_with.
    N(   R%   t   list_commandsRI   t   get_commandt   hidden(   R+   t   starts_withRM   R%   (    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt"   get_visible_commands_starting_with   s
    	c         C   s   t  |  j t  rM | j g  t |  |  D] } | j | j   f ^ q(  n  x |  j d  k	 r |  j }  t  |  j t  rP |  j j	 rP g  t |  |  D] } | j |  j
 k r | ^ q } | j g  | D] } | j | j   f ^ q  qP qP Wd  S(   N(   R$   R%   R   t   extendRT   R?   t   get_short_help_strR   R(   R&   R"   (   R+   RE   t   completions_outRM   t   remaining_commands(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   add_subcommand_completions   s    5	c         C   s  t  j |  } t |  | |  } | d k r1 g  St |  rv t | k rv | j t  } | j | d  | d } n | t k r d } n  g  } t |  rDx | j j	 D] } t
 | t  r | j r g  | j | j D]! }	 |	 | k s | j r |	 ^ q }
 | j g  |
 D]$ } | j |  r| | j f ^ q q q W| Sx6 | j j	 D]( } t | |  rQt | | | |  SqQWx9 | j j	 D]+ } t | j	 |  rt | | | |  SqWt | | |  t |  S(   s   
    :param cli: command definition
    :param prog_name: the program that is running
    :param args: full list of args
    :param incomplete: the incomplete text to autocomplete
    :return: all the possible completions for the incomplete
    i    i   R   N(   t   copyt   deepcopyR/   R(   R1   R5   t	   partitiont   appendR%   t   paramsR$   R   RR   R7   t   secondary_optst   multipleRU   RI   t   helpR>   RO   RD   RY   t   sorted(   R*   R   R#   RE   R8   R+   t   partition_incompletet   completionst   paramt	   param_optt
   param_optst   o(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   get_choices   s4    		/?c         C   s   t  t j d  } t t j d  } | d | !} y | | } Wn t k
 rZ d } n XxR t |  | | |  D]; } t | d  | rq t | d r | d n d  qq qq Wt S(   Nt
   COMP_WORDSt
   COMP_CWORDi   R   i    R
   (   R   t   ost   environt   intt
   IndexErrorRi   R    R!   (   R*   R   t   include_descriptionst   cwordst   cwordR#   RE   t   item(    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   do_complete  s    
%c         C   ss   | j  d  rA | d k r! d n d } t t | | |   t S| d k sY | d k ro t |  | | d k  St S(   Nt   sourcet
   source_zshR   t   basht   completet   complete_zsh(   RI   R    R   R!   Rt   R)   (   R*   R   R   t   complete_instrR   (    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   bashcomplete  s    (    RZ   Rl   t   ret   utilsR    t   parserR   t   coreR   R   R   t   typesR   t   collectionsR   t   ImportErrorR5   R   R   t   compileR   R   R/   R1   R>   RD   RO   RT   RY   Ri   Rt   R{   (    (    (    s2   lib/python2.7/site-packages/click/_bashcomplete.pyt   <module>   s2   	
	%							.	