Ë
    ü[;jx>  ã                   ó    — 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m	Z	 dd„Z
dd„Zdd	„Zdd
„Zdd„Zd„ Zdd„Zd„ Zdd„Zd„ Zd„ Zy)z?Provides tab completion functionality for CLIs built with Fire.é    )Úabsolute_import)Údivision)Úprint_functionN)Úinspectutilsc                 ód   — |dk(  rt        | t        |«      |«      S t        | t        |«      |«      S )NÚfish)Ú_FishScriptÚ	_CommandsÚ_BashScript)ÚnameÚ	componentÚdefault_optionsÚshells       úXG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\fire/completion.pyÚScriptr      s1   € Ø
ˆf‚_Ü�tœY yÓ1°?ÓCÐCÜ	�Tœ9 YÓ/°Ó	AÐAó    c                 ó.  ‡ ‡‡— |xs
 t        «       }t        ‰ ||«      \  }}}d}d}d}dŠdŠˆ ˆˆfd„}	g }
t        «       }|j                  ‰ «       |j                  t        |j	                  «       «      «      }|j                  t        |j	                  «       «      «      }|D ]i  } |	|«      j                  dj                  t        ||   j                  ||   «      «      «      ¬«      }|
j                  |j                  ||¬	«      «       Œk d
j                  |
«      }|j                  |¬«      }|j                  ‰ ‰ |dj                  |«      ‰ j                  dd«      j                  dd«      j                  dd«      dj                  |«      ¬«      S )aX  Returns a Bash script registering a completion function for the commands.

  Args:
    name: The first token in the commands, also the name of the command.
    commands: A list of all possible commands that tab completion can complete
        to. Each command is a list or tuple of the string tokens that make up
        that command.
    default_options: A dict of options that can be used with any command. Use
        this if there are flags that can always be appended to a command.
  Returns:
    A string which is the Bash script. Source the bash script to enable tab
    completion in Bash.
  aâ  # bash completion support for {name}
# DO NOT EDIT.
# This script is autogenerated by fire/completion.py.

_complete-{identifier}()
{{
  local cur prev opts lastcommand
  COMPREPLY=()
  prev="${{COMP_WORDS[COMP_CWORD-1]}}"
  cur="${{COMP_WORDS[COMP_CWORD]}}"
  lastcommand=$(get_lastcommand)

  opts="{default_options}"
  GLOBAL_OPTIONS="{global_options}"

{checks}

  COMPREPLY=( $(compgen -W "${{opts}}" -- ${{cur}}) )
  return 0
}}

get_lastcommand()
{{
  local lastcommand i

  lastcommand=
  for ((i=0; i < ${{#COMP_WORDS[@]}}; ++i)); do
    if [[ ${{COMP_WORDS[i]}} != -* ]] && [[ -n ${{COMP_WORDS[i]}} ]] && [[
      ${{COMP_WORDS[i]}} != $cur ]]; then
      lastcommand=${{COMP_WORDS[i]}}
    fi
  done

  echo $lastcommand
}}

filter_options()
{{
  local opts
  opts=""
  for opt in "$@"
  do
    if ! option_already_entered $opt; then
      opts="$opts $opt"
    fi
  done

  echo $opts
}}

option_already_entered()
{{
  local opt
  for opt in ${{COMP_WORDS[@]:0:$COMP_CWORD}}
  do
    if [ $1 == $opt ]; then
      return 0
    fi
  done
  return 1
}}

is_prev_global()
{{
  local opt
  for opt in $GLOBAL_OPTIONS
  do
    if [ $opt == $prev ]; then
      return 0
    fi
  done
  return 1
}}

complete -F _complete-{identifier} {command}
z;
  case "${{lastcommand}}" in
  {lastcommand_checks}
  esaczQ
    {command})
      {opts_assignment}
      opts=$(filter_options $opts)
    ;;z‚
      if is_prev_global; then
        opts="${{GLOBAL_OPTIONS}}"
      else
        opts="{options} ${{GLOBAL_OPTIONS}}"
      fiz,
      opts="{options} ${{GLOBAL_OPTIONS}}" c                 ó   •— | ‰k(  r‰S ‰S ©N© )Úcommandr   Ú%opts_assignment_main_command_templateÚ#opts_assignment_subcommand_templates    €€€r   Ú_GetOptsAssignmentTemplatez/_BashScript.<locals>._GetOptsAssignmentTemplate—   s   ø€ Ø�$‚Ø2Ð2à0Ð0r   Ú )Úoptions)r   Úopts_assignmentÚ
)Úlastcommand_checksÚ/Ú Ú.Ú,)r   r   Úchecksr   Ú
identifierÚglobal_options)
ÚsetÚ_GetMapsÚaddÚunionÚkeysÚformatÚjoinÚsortedÚappendÚreplace)r   Úcommandsr   r&   Úoptions_mapÚsubcommands_mapÚbash_completion_templateÚcheck_wrapperÚlastcommand_check_templater   ÚlinesÚcommands_setr   r   r   r$   r   r   s   `               @@r   r   r   "   s°  ú€ ð $Ò,¤s£u€/Ü19Ø
ˆH�oó2Ñ.€.�+˜ðKÐðZ
€-ð
 
Ðð)Ð%ð+/Ð'ö1ð €%Ü“€,Ø×Ñ�4ÔØ×#Ñ#¤C¨×(<Ñ(<Ó(>Ó$?Ó@€,Ø×#Ñ#¤C¨×(8Ñ(8Ó(:Ó$;Ó<€,Û€gÙ0°Ó9×@Ñ@Ø—‘Ü�;˜wÑ'×-Ñ-¨o¸gÑ.FÓGÓHó
ð Aó €Oð
 
‡L�LØ"×)Ñ)ØØ+ð 	*ó 	-õð ð —y‘y Ó'Ðà×ÑØ+ð  ó €&ð
 ×%Ñ%ØØØØŸ(™( ?Ó3Ø—\‘\ # rÓ*×2Ñ2°3¸Ó;×CÑCÀCÈÓLØŸ™ .Ó1ð &ó ð	r   c                 óü  — |xs
 t        «       }t        | ||«      \  }}}d}d}d}d}	t        |j                  «       «      j                  t        |j                  «       «      «      D ]l  }
||
   D ]  }||j	                  | |
|¬«      z  }Œ ||
   j                  |«      D ]2  }|
| k7  }||j	                  | |
|r|	nd|j                  d«      ¬«      z  }Œ4 Œn |j	                  d	j                  d
„ |D «       «      ¬«      S )aX  Returns a Fish script registering a completion function for the commands.

  Args:
    name: The first token in the commands, also the name of the command.
    commands: A list of all possible commands that tab completion can complete
        to. Each command is a list or tuple of the string tokens that make up
        that command.
    default_options: A dict of options that can be used with any command. Use
        this if there are flags that can always be appended to a command.
  Returns:
    A string which is the Fish script. Source the fish script to enable tab
    completion in Fish.
  aL  function __fish_using_command
    set cmd (commandline -opc)
    for i in (seq (count $cmd) 1)
        switch $cmd[$i]
        case "-*"
        case "*"
            if [ $cmd[$i] = $argv[1] ]
                return 0
            else
                return 1
            end
        end
    end
    return 1
end

function __option_entered_check
    set cmd (commandline -opc)
    for i in (seq (count $cmd))
        switch $cmd[$i]
        case "-*"
            if [ $cmd[$i] = $argv[1] ]
                return 1
            end
        end
    end
    return 0
end

function __is_prev_global
    set cmd (commandline -opc)
    set global_options {global_options}
    set prev (count $cmd)

    for opt in $global_options
        if [ "--$opt" = $cmd[$prev] ]
            echo $prev
            return 0
        end
    end
    return 1
end

zJcomplete -c {name} -n '__fish_using_command {command}' -f -a {subcommand}
z}complete -c {name} -n '__fish_using_command {command};{prev_global_check} and __option_entered_check --{option}' -l {option}
z and __is_prev_global;)r   r   Ú
subcommandr!   ú--)r   r   Úprev_global_checkÚoptionr   c              3   ó(   K  — | ]
  }d |› d �–— Œ y­w)Ú"Nr   )Ú.0r=   s     r   Ú	<genexpr>z_FishScript.<locals>.<genexpr>  s   è ø€ ÐI¹.°  & ¨œm¹.ùs   ‚)r&   )r'   r(   r+   r*   r,   Úlstripr-   )r   r1   r   r&   r2   r3   Úfish_sourceÚsubcommand_templateÚflag_templater<   r   r:   r=   Úcheck_neededs                 r   r	   r	   ¿   s6  € ð $Ò,¤s£u€/Ü19Ø
ˆH�oó2Ñ.€.�+˜ð+€+ðZ;ÐðF€-ð /ÐÜ�_×)Ñ)Ó+Ó,×2Ñ2´3°{×7GÑ7GÓ7IÓ3JÖK€gØ% gÔ.ˆ
ØÐ(×/Ñ/ØØØð 0ó ñ �kð /ð ˜gÑ&×,Ñ,¨^Ö<ˆØ ‘_€lØ�]×)Ñ)ØØÙ1=Ñ-À2Ø—‘˜tÓ$ð	 *ó ñ �kñ =ð Lð" 
×	Ñ	Ø—X‘XÑI¹.ÓIÓIð 
ó 
ð r   c                 ó6  — t        |t        «      r|j                  d«      ry|ry|t        u s|t        u s|t
        u ryt        |t        t        «      «      ryg }t        j                  |«      r||v ryt        j                  | «      rn|€t        j                  | «      xs i }|j                  |«      }|r@|j                  dv ryt        t        dt        d«      «      }t        |j                   |«      ryt        |t        «      r|j                  d«       S y)a¶  Returns whether a member should be included in auto-completion or help.

  Determines whether a member of an object with the specified name should be
  included in auto-completion or help text(both usage and detailed help).

  If the member name starts with '__', it will always be excluded. If it
  starts with only one '_', it will be included for all non-string types. If
  verbose is True, the members, including the private members, are included.

  When not in verbose mode, some modules and functions are excluded as well.

  Args:
    component: The component containing the member.
    name: The name of the member.
    member: The member itself.
    class_attrs: (optional) If component is a class, provide this as:
      inspectutils.GetClassAttrsDict(component). If not provided, it will be
      computed.
    verbose: Whether to include private members.
  Returns
    A boolean value indicating whether the member should be included.
  Ú__FTN)ÚmethodÚpropertyÚ_tuplegetterÚ_)Ú
isinstanceÚstrÚ
startswithr   r   r   ÚtypeÚinspectÚismoduleÚisclassr   ÚGetClassAttrsDictÚgetÚkindÚgetattrÚcollectionsÚobject)r   r   ÚmemberÚclass_attrsÚverboseÚmodules_to_hideÚ
class_attrÚtuplegetters           r   ÚMemberVisibler`     sü   € ô. �”cÔ˜tŸ™¨tÔ4ØÙØØ”ÑØ	”8Ñ	Ø	”>Ñ	!ØÜ�œœ_Ó-Ô.Øà€/Ü×Ñ�fÔ &¨OÑ";ØÜ‡_�_�YÔàÐÜ ×2Ñ2°9Ó=ÒCÀ€kØ—‘ Ó&€JÙð 
�‰Ð2Ñ	2Øô œK¨¼¸d»ÓD€kÜ	�J×%Ñ% {Ô	3ØÜ�”cÔØ�‰˜sÓ#Ð#Ð#Ø	r   c                 óö   — t        | t        «      r| j                  «       }nt        j                  | «      }|€t        j                  | «      }|D ��cg c]  \  }}t        | ||||¬«      r||f‘Œ c}}S c c}}w )a  Returns a list of the members of the given component.

  If verbose is True, then members starting with _ (normally ignored) are
  included.

  Args:
    component: The component whose members to list.
    class_attrs: (optional) If component is a class, you may provide this as:
      inspectutils.GetClassAttrsDict(component). If not provided, it will be
      computed. If provided, this determines how class members will be treated
      for visibility. In particular, methods are generally hidden for
      non-instantiated classes, but if you wish them to be shown (e.g. for
      completion scripts) then pass in a different class_attr for them.
    verbose: Whether to include private members.
  Returns:
    A list of tuples (member_name, member) of all members of the component.
  ©r[   r\   )rM   ÚdictÚitemsrQ   Ú
getmembersr   rT   r`   )r   r[   r\   ÚmembersÚmember_namerZ   s         r   ÚVisibleMembersrh   U  sƒ   € ô$ �	œ4Ô Ø�o‰oÓ�Gä× Ñ  Ó+€Gð ÐÜ×0Ñ0°Ó;€Ká7>ô
Ù7>Ñ 3 ¨VÜ	�y +¨vÀ;Ø&õ
(ð �FÒ°wò
ð ùó 
s   ÁA5c                 ód   — g }| D ](  }|j                  dd«      }|j                  d|› �«       Œ* |S )zÖTakes a list of fn args and returns a list of the fn's completion strings.

  Args:
    fn_args: A list of the args accepted by a function.
  Returns:
    A list of possible completion strings for that function.
  rL   Ú-r;   )r0   r/   )Úfn_argsÚcompletionsÚargs      r   Ú_CompletionsFromArgsrn   v  s?   € ð €+Û€cØ
�+‰+�c˜3Ó
€CØ×Ñ˜˜C˜5�zÕ"ð ð 
Ðr   c                 óÜ  — t        j                  | «      st        j                  | «      r7t        j                  | «      }t        |j                  |j                  z   «      S t        | t        t        f«      r+t        t        | «      «      D �cg c]  }t        |«      ‘Œ c}S t        j                  | «      rg S t        | |¬«      D ��cg c]  \  }}t!        |«      ‘Œ c}}S c c}w c c}}w )a´  Gives possible Fire command completions for the component.

  A completion is a string that can be appended to a command to continue that
  command. These are used for TAB-completions in Bash for Fire CLIs.

  Args:
    component: The component whose completions to list.
    verbose: Whether to include all completions, even private members.
  Returns:
    A list of completions for a command that would so far return the component.
  ©r\   )rQ   Ú	isroutinerS   r   ÚGetFullArgSpecrn   ÚargsÚ
kwonlyargsrM   ÚtupleÚlistÚrangeÚlenrN   Úisgeneratorrh   Ú_FormatForCommand)r   r\   ÚspecÚindexrg   rL   s         r   ÚCompletionsr}   …  sÆ   € ô ×Ñ�yÔ!¤W§_¡_°YÔ%?Ü×&Ñ& yÓ1€DÜ §	¡	¨D¯O©OÑ ;Ó<Ð<ä�	œE¤4˜=Ô)Ü$)¬#¨i«.Ô$9Ó:Ñ$9˜5ŒC��JÐ$9Ñ:Ð:ä×Ñ˜Ô#à€Iô +¨9¸gÕFô
áF‰.ˆ+�qô ˜Õ$ØFò
ð ùò ;ùó
s   ÂC#Ã
C(c                 ó‚   — t        | t        «      st        | «      } | j                  d«      r| S | j                  dd«      S )aÈ  Replaces underscores with hyphens, unless the token starts with a token.

  This is because we typically prefer hyphens to underscores at the command
  line, but we reserve hyphens at the start of a token for flags. This becomes
  relevant when --verbose is activated, so that things like __str__ don't get
  transformed into --str--, which would get confused for a flag.

  Args:
    token: The token to transform.
  Returns:
    The transformed token.
  rL   rj   )rM   rN   rO   r0   )Útokens    r   rz   rz   ¢  s;   € ô 
�Eœ3Ô	Ü�‹J€Eà
×Ñ�cÔØ€Là	�‰�s˜CÓ	 Ð r   c              #   óJ  K  — t        j                  | «      st        j                  | «      rt        | d¬«      D ]  }|f–— Œ	 t        j                  | «      ry|dk  ryt	        | i d¬«      D ]1  \  }}t        |«      }|f–— t        ||dz
  «      D ]
  }|f|z   –— Œ Œ3 y­w)a	  Yields tuples representing commands.

  To use the command from Python, insert '.' between each element of the tuple.
  To use the command from the command line, insert ' ' between each element of
  the tuple.

  Args:
    component: The component considered to be the root of the yielded commands.
    depth: The maximum depth with which to traverse the member DAG for commands.
  Yields:
    Tuples, each tuple representing one possible command for this CLI.
    Only traverses the member DAG up to a depth of depth.
  Frp   Né   rb   )rQ   rq   rS   r}   rh   rz   r
   )r   ÚdepthÚ
completionrg   rZ   r   s         r   r
   r
   ¸  s¨   è ø€ ô ×Ñ�yÔ!¤W§_¡_°YÔ%?Ü! )°U×;ˆ
ØˆMÓð <ä×Ñ�yÔ!Ø
à
ˆQ‚YØ
ô ,¨IÀ2Ø49÷;Ñ€k�6ô $ KÓ0€Kàˆ.Òä˜V U¨Q¡YÖ/ˆØˆN˜WÑ$Ó$ñ 0ñ;ùs   ‚B!B#c                 ó$   — | j                  d«      S )Nrj   )rO   )rm   s    r   Ú	_IsOptionr…   Û  s   € Ø	�‰˜Ó	Ðr   c                 óö  ‡— t        j                   ‰«      }t        j                  ˆfd„«      }t        j                  t        «      }|D ]©  }t	        |«      dk(  r;t        |d   «      r|j                  |d   «       Œ4||    j                  |d   «       ŒL|sŒO|d   }t        |d   «      }t        |«      r|}	n|}	|	|   j                  |«       |	|j                  dd«         j                  |«       Œ« |||fS )aÐ  Returns sets of subcommands and options for each command.

  Args:
    name: The first token in the commands, also the name of the command.
    commands: A list of all possible commands that tab completion can complete
        to. Each command is a list or tuple of the string tokens that make up
        that command.
    default_options: A dict of options that can be used with any command. Use
        this if there are flags that can always be appended to a command.
  Returns:
    global_options: A set of all options of the first token of the command.
    subcommands_map: A dict storing set of subcommands for each
        command/subcommand.
    options_map: A dict storing set of options for each subcommand.
  c                  ó.   •— t        j                   ‰ «      S r   )Úcopy)r   s   €r   Ú<lambda>z_GetMaps.<locals>.<lambda>ð  s   ø€ ´·	±	¸/Ô0Jr   r�   r   éþÿÿÿéÿÿÿÿrL   rj   )	rˆ   rX   Údefaultdictr'   rx   r…   r)   rz   r0   )
r   r1   r   r&   r2   r3   r   r:   rm   Úargs_maps
     `       r   r(   r(   ß  sì   ø€ ô  —9‘9˜_Ó-€.Ü×'Ñ'Ó(JÓK€+Ü×+Ñ+¬CÓ0€/ã€gÜ
ˆ7ƒ|�qÒÜ	�7˜1‘:Ô	Ø×Ñ˜7 1™:Õ&à˜Ñ×!Ñ! '¨!¡*Õ-â	Ø˜2‘;€jÜ˜g b™kÓ*€cä	�3ŒØ‰à"ˆàˆzÑ×Ñ˜sÔ#Øˆz×!Ñ! # sÓ+Ñ,×0Ñ0°Õ5ð# ð& 
˜ oÐ	5Ð5r   )NÚbashr   )NF)F)é   )Ú__doc__Ú
__future__r   r   r   rX   rˆ   rQ   Úfirer   r   r   r	   r`   rh   rn   r}   rz   r
   r…   r(   r   r   r   Ú<module>r“      s_   ðñ Få &Ý Ý %ã Û Û å óBóZózZóz6óròBóò:!ó, %òFó'6r   