
    ix>                         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dS )z?Provides tab completion functionality for CLIs built with Fire.    )absolute_import)division)print_functionN)inspectutilsbashc                     |dk    rt          | t          |          |          S t          | t          |          |          S )Nfish)_FishScript	_Commands_BashScript)name	componentdefault_optionsshells       V/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/fire/completion.pyScriptr      s?    
f__tYy11?CCC	T9Y//	A	AA    c                     |pt                      }t           ||          \  }}}d}d}d}dd fd}	g }
t                      }|                                |                    t          |                                                    }|                    t          |                                                    }|D ]} |	|                              d                    t          ||                             ||                                                 }|
                    |                    ||	                     d
                    |
          }|                    |          }|                      |d                    |           	                    dd          	                    dd          	                    dd          d                    |                    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<    $,suu/19
Ho2 2..+KZ
-
 
)%+/'1 1 1 1 1 1 1 %,4##C(<(<(>(>$?$?@@,##C(8(8(:(:$;$;<<, 
 
g0099@@;w'--og.FGGHH
 
 A  O
 
LL"))+ 	* 	- 	-   
 yy''+    &
 %%((?33\\#r**223;;CCCLL.11 &  	r   c                 h   |pt                      }t          | ||          \  }}}d}d}d}d}	t          |                                                              t          |                                                    D ]}
||
         D ]}||                    | |
|          z  }||
                             |          D ];}|
| k    }||                    | |
|r|	nd|                    d                    z  }<|                    d	                    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 V  dS )"Nr   ).0r>   s     r   	<genexpr>z_FishScript.<locals>.<genexpr>  s*      IIm&mmmIIIIIIr   )r'   )r(   r)   r,   r+   r-   lstripr.   )r   r2   r   r'   r3   r4   fish_sourcesubcommand_templateflag_templater=   r   r;   r>   check_neededs                 r   r
   r
      s    $,suu/19
Ho2 2..+++Z;F- /_))++,,223{7G7G7I7I3J3JKK  g%g.  
(// 0   kk g&,,^<<  _l]))1=E--2t$$	 *   kk 
		XXII.IIIII 
 
 
 r   Fc                    t          |t                    r|                    d          rdS |rdS |t          u s|t          u s	|t
          u rdS t          |t          t                              rdS g }t          j        |          r||v rdS t          j	        |           rt|t          j        |           pi }|                    |          }|rE|j        dv rdS t          t          dt          d                    }t          |j        |          rdS t          |t                    r|                    d           S dS )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   MemberVisiblera     sa   . c tt44 5 4	8			>	!	!5_--.. 5/f &O";";5_Y  29==Ck&&J 	 
2	2	2u KdDDk	J%{	3	3 uc $s####	r   c                      t           t                    r                                 }nt          j                   }t          j                    fd|D             S )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.
  Nc           	      F    g | ]\  }}t          ||           ||fS )r\   r]   )ra   )rA   member_namer[   r\   r   r]   s      r   
<listcomp>z"VisibleMembers.<locals>.<listcomp>o  sR     
 
 
 3V	y+v;&
( 
( 
(
F
 
 
r   )rN   dictitemsrR   
getmembersr   rU   )r   r\   r]   memberss   ``` r   VisibleMembersrk   U  s    $ 	4   ,ooGG ++G 0;;K
 
 
 
 
 
7>
 
 
 r   c                 p    g }| D ]0}|                     dd          }|                    d|            1|S )zTakes 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.
  rM   -r<   )r1   r0   )fn_argscompletionsargs      r   _CompletionsFromArgsrq   v  sN     + # #c
++c3

CzCzz""""	r   c                    t          j        |           st          j        |           r0t          j        |           }t          |j        |j        z             S t          | t          t          f          r&d t          t          |                     D             S t          j        |           rg S d t          | |          D             S )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.
  c                 ,    g | ]}t          |          S r   )rO   )rA   indexs     r   rf   zCompletions.<locals>.<listcomp>  s    :::5CJJ:::r   c                 2    g | ]\  }}t          |          S r   )_FormatForCommand)rA   re   rM   s      r   rf   zCompletions.<locals>.<listcomp>  s4     
 
 

+q $$
 
 
r   r]   )rR   	isroutinerT   r   GetFullArgSpecrq   args
kwonlyargsrN   tuplelistrangelenisgeneratorrk   )r   r]   specs      r   Completionsr     s     y!! =W_Y%?%? =&y11D	DO ;<<<	E4=)) ;::E#i..$9$9::::## I
 
*9gFFF
 
 
 r   c                     t          | t                    st          |           } |                     d          r| S |                     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.
  rM   rm   )rN   rO   rP   r1   )tokens    r   rv   rv     sP     
E3		 JJE
c L	sC	 	  r      c              #   \  K   t          j        |           st          j        |           rt          | d          D ]}|fV  t          j        |           rdS |dk     rdS t	          | i d          D ]7\  }}t          |          }|fV  t          ||dz
            D ]
}|f|z   V  8dS )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.
  Frw   N   rd   )rR   rx   rT   r   rk   rv   r   )r   depth
completionre   r[   r   s         r   r   r     s
      y!! W_Y%?%? !)U;;;  
My!! 
F
QYY
F ,I249; ; ; % %k6 $K00K.VUQY// % %NW$$$$$%% %r   c                 ,    |                      d          S )Nrm   )rP   )rp   s    r   	_IsOptionr     s    			r   c                 f   t          j                   }t          j        fd          }t          j        t                    }|D ]}t	          |          dk    rSt          |d                   r|                    |d                    F||                              |d                    h|r{|d         }t          |d                   }t          |          r|}	n|}	|	|                             |           |	|                    dd                                       |           |||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    	/0J0J r   r   r   rM   rm   )	r   rY   defaultdictr(   r   r   r*   rv   r1   )
r   r2   r   r'   r3   r4   r   r;   rp   args_maps
     `       r   r)   r)     s9     9_--.'(J(J(J(JKK++C00/ 6 6g
7||q	71:		 .71:&&&&!!'!*----	 
62;jgbk**c	3 #"zs###z!!#s++,00555	o	55r   )Nr   r   )NF)F)r   )__doc__
__future__r   r   r   rY   r   rR   firer   r   r   r
   ra   rk   rq   r   rv   r   r   r)   r   r   r   <module>r      sW   F E & & & & & &       % % % % % %            B B B BZ Z Z ZzZ Z Z Zz6 6 6 6r   B     :! ! !, %  %  %  %F  '6 '6 '6 '6 '6r   