+
    Q(i>                        R t ^ RIt^ RIHt ^ RIHtHtHtHtH	t	H
t
 ]'       d   ^ RIHt ^ RIHt R R ltR R	 ltR
 R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR  R! ltR# )"zFish completion script generator.

Generates static fish completion scripts using `complete -c COMMAND` statements.
Completions auto-load from ~/.config/fish/completions/PROGNAME.fish.
N)TYPE_CHECKING)CompletionActionCompletionDataclean_choice_textextract_completion_dataget_completion_actionstrip_markup)App)CommandSpecc                4    V ^8  d   QhRRR\         R\         /# )   appr	   	prog_namereturnstr)formats   "^/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/cyclopts/completion/fish.py__annotate__r      s!     )# )#E )#c )#c )#    c                   V'       d   \         P                  ! RV4      '       g   \        RV: R24      h\        V 4      pRV 2RR.p\        ;QJ d*    R VP                  4        4       F  '       g   K   RM	  R	M! R VP                  4        4       4      pV'       d,   VP                  \        W4      4       VP                  R4       V P                  '       d   \        V P                  4      MRpV P                  '       d   \        V P                  4      MRpVP                  \        W!WV4      4       R
P                  V4      R
,           # )aV  Generate fish completion script.

Parameters
----------
app : App
    The Cyclopts application to generate completion for.
prog_name : str
    Program name for completion (alphanumeric with hyphens/underscores).

Returns
-------
str
    Complete fish completion script.

Raises
------
ValueError
    If prog_name contains invalid characters.
z^[a-zA-Z0-9_-]+$zInvalid prog_name: z0. Must be alphanumeric with hyphens/underscores.z# Fish completion for z# Generated by Cyclopts c              3   >   "   T F  p\        V4      ^ 8  x  K  	  R# 5i)    N)len).0paths   & r   	<genexpr>-generate_completion_script.<locals>.<genexpr>7   s     O8Nc$i!m8Ns   TF
 )rematch
ValueErrorr   anykeysextend_generate_helper_functionsappend
help_flagstupleversion_flags_generate_completionsjoin)r   r   completion_datalineshas_nested_commandsr)   r+   s   &&     r   generate_completion_scriptr1      s   ( BHH%8)DD.ym;klmm-c2O !,!
E #O8L8L8NO###O8L8L8NOO/	KLR*-...s~~&bJ030A0A0AE#++,rM	LL&:]^99Ud""r   c                0    V ^8  d   QhR\         R\         /# r   textr   r   )r   s   "r   r   r   D   s     & &c &c &r   c                &    V P                  RR4      # )z&Escape single quotes for fish strings.'z'\'')replacer4   s   &r   _escape_fish_stringr9   D   s    <<W%%r   c                0    V ^8  d   QhR\         R\         /# r3   r   )r   s   "r   r   r   I   s     % %3 %3 %r   c                `    V P                  RR4      p V P                  RR4      p \        V 4      # )z!Escape description text for fish.r    )r7   r9   r8   s   &r   _escape_fish_descriptionr>   I   s-    <<c"D<<c"Dt$$r   c                    V ^8  d   QhR\         R\        \        \         R3,          \        3,          R\        \         ,          /# )r   r   r.   .r   )r   dictr*   r   list)r   s   "r   r   r   P   sA     I II%S/>9:I 
#YIr   c                L   \        4       pVP                  4        F  pVP                   F  pVP                  4       '       d   K  VP                  P
                  '       g   K9  VP                  P
                   F-  pVP                  R4      '       g   K  VP                  V4       K/  	  K  	  K  	  RV  R2pRRV 2RR.pV'       d8   RP                  R	 \        V4       4       4      pVP                  R
V R24       MVP                  R4       VP                  . RO4       V# )a  Generate helper function for command path detection.

Parameters
----------
prog_name : str
    Program name.
completion_data : dict
    Completion data used to identify options that take values.

Returns
-------
list[str]
    Lines defining the helper function.
-__fish__using_commandz6# Helper function to check exact command path sequencez	function z!    set -l cmd (commandline -opc)z    set -l subcommandsr<   c              3   8   "   T F  p\        V4      x  K  	  R # 5iNr9   )r   opts   & r   r   -_generate_helper_functions.<locals>.<genexpr>s   s     `D_S 3C 8 8D_   z     set -l options_with_values 'r6   z!    set -l options_with_values '')z    set -l skip_next 0z;    # Extract non-option words (commands) from command linez!    for i in (seq 2 (count $cmd))z        set -l word $cmd[$i]z         if test $skip_next -eq 1z            set skip_next 0z            continue        endz)        if string match -qr -- '^-' $wordz>            # Check if this option takes a value (exact match)zF            if string match -q -- "* $word *" " $options_with_values "z                set skip_next 1z            endz        elsez*            # Non-option word is a commandz$            set -a subcommands $wordrL       endz8    # Check if subcommand sequence matches expected pathz2    if test (count $subcommands) -ne (count $argv)z        return 1rM   z"    for i in (seq 1 (count $argv))z-        if test $subcommands[$i] != $argv[$i]z            return 1rL   rM   z    return 0end)setvalues	argumentsis_flag	parametername
startswithaddr-   sortedr(   r&   )	r   r.   options_with_valuesdataargumentrT   	func_namer/   escaped_optss	   &&       r   r'   r'   P   s   $ %&&(H##%%(*<*<*A*A*A$..33Ds+++//5 4 ' ) )N3I@
I;+ 	E xx`FK^D_``7~QGH89	LL	
 B Lr   c                0    V ^8  d   QhR\         R\        /# )r   actionr   )r   r   )r   s   "r   r   r      s      +;  r   c                b    V \         P                  8X  d   R# V \         P                  8X  d   R# R# )zMap completion action to fish flags.

Parameters
----------
action : CompletionAction
    Completion action type.

Returns
-------
str
    Fish completion flags ("-r -F" for files, "-r -a '(...)'" for directories, "" otherwise).
z-r -Fz%-r -a '(__fish_complete_directories)'r   )r   FILESDIRECTORIES)r^   s   &r   _map_completion_action_to_fishrb      s+     !'''!---6r   c                    V ^8  d   QhR\         \        \        R3,          \        3,          R\        R\        \        R3,          R\        \        R3,          R\        \        ,          /# )r   r.   .r   r)   r+   r   r@   r*   r   r   rA   )r   s   "r   r   r      s`     ' '%S/>9:'' c3h' c?	'
 
#Y'r   c           
         . p\        V P                  4       4       FZ  w  rVVP                  \        V VVVV4      4       V\	        V P                  4       \        R7      8w  g   KI  VP                  R4       K\  	  V# )a/  Generate all fish completion commands.

Parameters
----------
completion_data : dict
    Extracted completion data.
prog_name : str
    Program name.
help_flags : tuple[str, ...]
    Help flags.
version_flags : tuple[str, ...]
    Version flags.

Returns
-------
list[str]
    Completion command lines.
)keyr   )rW   itemsr&   _generate_completions_for_pathmaxr%   r   r(   )r.   r   r)   r+   r/   command_path_datas   &&&&   r   r,   r,      st    0 E%o&;&;&=>*	
 33353??LL  ? Lr   c                    V ^8  d   QhR\         \        \        R3,          \        3,          R\        \        R3,          R\        R\        \        R3,          R\        \        R3,          R\        \        ,          /# )r   r.   .rj   r   r)   r+   r   rd   )r   s   "r   r   r      sr     + +%S/>9:+S/+ + c3h	+
 c?+ 
#Y+r   c                P   W9  d   . # W,          p. p\        W4      pVP                  \        WQW'4      4       VP                   Uu. uF0  qP	                  4       '       d   K  VP
                  '       g   K.  VNK2  	  p	pV	'       g   V'       g	   V'       d   VP                  \        V4      4       VP                  \        W'W44      4       VP                  \        WWuP                  4      4       VP                  \        VP                  W'VP                  4      4       V# u upi )ak  Generate completions for a specific command path.

Parameters
----------
completion_data : dict
    Extracted completion data.
command_path : tuple[str, ...]
    Command path.
prog_name : str
    Program name.
help_flags : tuple[str, ...]
    Help flags.
version_flags : tuple[str, ...]
    Version flags.

Returns
-------
list[str]
    Completion command lines.
)_get_condition_for_pathr&    _generate_subcommand_completionsrQ   is_positional_onlyshow_generate_option_section_header"_generate_help_version_completions!_generate_keyword_arg_completionshelp_format$_generate_command_option_completionscommands)
r.   rj   r   r)   r+   rY   r/   	conditionargkeyword_argss
   &&&&&     r   rh   rh      s    6 *	(DE'@I	LL1$i[\#'>>_>C9O9O9QCVYV^V^CC>L_z]4\BC7	jhi6|PY[k[klm9$--_c_o_opqL `s   D##D#7D#c                    V ^8  d   QhR\         R\        \        R3,          R\        R\        R\        \        ,          /# )r   rY   rj   .r   rx   r   )r   r*   r   rA   )r   s   "r   r   r     sF     / /
/S// / 	/
 
#Y/r   c                X   V P                    UUu. uF/  qDP                   F  qUP                  R4      '       d   K  VNK  	  K1  	  pppV'       g   . # . pV'       d%   VP                  RRP	                  V4       24       MVP                  R4       V P                    F  pVP                   Fp  pVP                  R4      '       d   K  \        VP                  V P                  4      p	\        V	4      p
\        V4      pVP                  RV RV RV RV
 R2	4       Kr  	  K  	  V# u uppi )	a  Generate completions for subcommands.

Parameters
----------
data : CompletionData
    Completion data.
command_path : tuple[str, ...]
    Command path.
prog_name : str
    Program name.
condition : str
    Fish condition.

Returns
-------
list[str]
    Completion command lines.
rC   z# Subcommands for: r<   z# Root-level commandscomplete -c z -a '' -d 'r6   )
rw   namesrU   r(   r-   _get_description_from_appr   ru   r>   r9   )rY   rj   r   rx   registered_commandrT   rw   r/   cmd_namedescescaped_descescaped_cmds   &&&&        r   ro   ro     s   2 (,}}'4#AYAYapapqtauAY}   	E*388L+A*BCD,-"mm*00H""3'',-?-C-CTEUEUVD3D9L-h7KLL<	{!I;eK=PVWcVddefg 1 , L/s
   &D&
D&c                `    V ^8  d   QhR\         \        R3,          R\        \        ,          /# )r   rj   .r   )r*   r   rA   )r   s   "r   r   r   :  s&     $ $%S/ $d3i $r   c                B    V '       d   RRP                  V 4       2.# R.# )zGenerate section header comment for options.

Parameters
----------
command_path : tuple[str, ...]
    Command path.

Returns
-------
list[str]
    Comment line.
z# Options for: r<   z# Root-level optionsr-   )rj   s   &r   rr   rr   :  s*     !#((<"8!9:;;"##r   c                    V ^8  d   QhR\         R\         R\        \         R3,          R\        \         R3,          R\        \         ,          /# )r   r   rx   r)   .r+   r   )r   r*   rA   )r   s   "r   r   r   L  sN     * *** c3h* c?	*
 
#Y*r   c           
     ^   . pV F  pVP                  R4      '       d'   VR,          pVP                  RV  RV RV R24       K@  VP                  R4      '       g   KY  \        V4      ^8X  g   Kk  V^,          pVP                  RV  RV RV R24       K  	  V F  pVP                  R4      '       d'   VR,          pVP                  RV  RV RV R	24       K@  VP                  R4      '       g   KY  \        V4      ^8X  g   Kk  V^,          pVP                  RV  RV RV R	24       K  	  V# )
a'  Generate completions for help and version flags.

Parameters
----------
prog_name : str
    Program name.
condition : str
    Fish condition.
help_flags : tuple[str, ...]
    Help flags.
version_flags : tuple[str, ...]
    Version flags.

Returns
-------
list[str]
    Completion command lines.
--r   NNr}   r<    -l z$ -d 'Display this message and exit.'rC    -s z" -d 'Display application version.')rU   r(   r   )r   rx   r)   r+   r/   flag	long_name
short_names   &&&&    r   rs   rs   L  s"   0 E??4  RILL<	{!I;d9+Mqrs__S!!c$i1naJLL<	{!I;d:,Nrst  ??4  RILL<	{!I;d9+Mopq__S!!c$i1naJLL<	{!I;d:,Npqr  Lr   c                j    V ^8  d   QhR\         R\        R\        R\        R\         \        ,          /# )r   rz   r   rx   ru   r   rA   r   )r   s   "r   r   r   y  sE     I III I 	I
 
#YIr   c                "   . pV  EF  p\        VP                  P                  ;'       g    RVR7      p\        V4      pVP	                  4       pVP                  RR7      p	\        VP                  4      p
VP                  P                  ;'       g    .  EFE  pVP                  R4      '       g   K  VP                  R4      '       d   VR,          pRV R	V R
V 2.pM(\        V4      ^8X  d   V^,          pRV R	V RV 2.pMKr  V'       d   VP                  RV R24       MV	'       dN   V	 Uu. uF  p\        \        V4      4      NK  	  ppR	P                  V4      pVP                  RV RV R24       M@\        V
4      pV'       d   VP                  V RV R24       MVP                  RV R24       VP                  R	P                  V4      4       EKH  	  VP                    F  pVP                  R4      '       g   K  VP                  R4      '       d*   VR,          pVP                  RV R	V R
V RV R2	4       K\  \        V4      ^8X  g   Kn  V^,          pVP                  RV R	V RV RV R2	4       K  	  EK  	  V# u upi )a  Generate completions for keyword arguments.

Parameters
----------
keyword_args : list
    Keyword arguments.
prog_name : str
    Program name.
condition : str
    Fish condition.
help_format : str
    Help text format.

Returns
-------
list[str]
    Completion command lines.
r   r   T)forcerC   r   r   r}   r<   r   r   z-d 'r6   z-x -a 'r~    -d 'z-r -d ')r   rS   helpr>   rR   get_choicesr   hintrT   rU   r   r(   r9   r   r-   rb   	negatives)rz   r   rx   ru   r/   rZ   r   r   rR   choicesr^   rT   r   
line_partsr   cescaped_choiceschoices_straction_flagss   &&&&               r   rt   rt   y  sx   0 E H..3399r+N/5""$&&T&2&x}}5&&++11r1D??3''t$$ H	 ,YKq4	{ST
Ta!!W
 ,YKq4
|TU
!!Da"89V]"^V]QR#67H7K#LV]"^!hh7!!GK=|nA"NO=fE%%eL>&KL%%~Q&?@LL*-.5 28 &&D??3''t$$ H	|I;a	{$ykQVWcVddefgTa!!W
|I;a	{$zlRWXdWeefgh 'I !^ L/ #_s   2Jc                j    V ^8  d   QhR\         R\        R\        R\        R\         \        ,          /# )r   rw   r   rx   ru   r   r   )r   s   "r   r   r     s>     ) ))) ) 	)
 
#Y)r   c                   . pV  F  pVP                    F  pVP                  R4      '       g   K  \        VP                  V4      p\	        V4      pVP                  R4      '       d*   VR,          p	VP                  RV RV RV	 RV R2	4       K}  \        V4      ^8X  g   K  V^,          p
VP                  RV RV R	V
 RV R2	4       K  	  K  	  V# )
a.  Generate completions for commands that look like options.

Parameters
----------
commands : list
    List of RegisteredCommand tuples.
prog_name : str
    Program name.
condition : str
    Fish condition.
help_format : str
    Help text format.

Returns
-------
list[str]
    Completion command lines.
rC   r   r   r}   r<   r   r   r6   r   )r   rU   r   r   r>   r(   r   )rw   r   rx   ru   r/   r   r   r   r   r   r   s   &&&&       r   rv   rv     s    0 E&*00H&&s++,-?-C-C[QD3D9L""4(($RL	|I;a	{$ykQVWcVddefgX!#%a[
|I;a	{$zlRWXdWeefgh 1 ' Lr   c                V    V ^8  d   QhR\         \        R3,          R\        R\        /# )r   rj   .r   r   )r*   r   )r   s   "r   r   r     s)     2 2%S/ 2c 2c 2r   c                d    V '       g   R# RV R2pRP                  R V  4       4      pRV RV R2# )zGenerate fish condition string for a command path.

Parameters
----------
command_path : tuple[str, ...]
    Command path (empty for root).
prog_name : str
    Program name.

Returns
-------
str
    Fish condition flag.
z-n __fish_use_subcommandrD   rE   r<   c              3   8   "   T F  p\        V4      x  K  	  R # 5irG   rH   )r   cmds   & r   r   *_get_condition_for_path.<locals>.<genexpr>  s     QLS 3C 8 8LrK   z-n 'r6   r   )rj   r   r[   escaped_commandss   &&  r   rn   rn     sD     ))N3IxxQLQQ)A./q11r   c                4    V ^8  d   QhRRR\         R\         /# )r   cmd_appzApp | CommandSpecru   r   r   )r   s   "r   r   r     s#     2 2': 2 2QT 2r   c                    ^ RI Hp  V! V P                  R4      pVP                  ;'       g    Rp\        WAR7      #   \         d#    \        T P                  ;'       g    R4      p L8i ; i)zExtract description from App.

Parameters
----------
cmd_app : App | CommandSpec
    Command app or spec.
help_format : str
    Help text format.

Returns
-------
str
    Description text.
)docstring_parse	plaintextr   r   )cyclopts.help.helpr   r   short_description	Exceptionr   r   )r   ru   r   parsedr4   s   &&   r   r   r     sc     3' {;''--2 11  '7<<%%2&'s   %= = "A* A*)A*)__doc__r!   typingr   cyclopts.completion._baser   r   r   r   r   r   cycloptsr	   cyclopts.command_specr
   r1   r9   r>   r'   rb   r,   rh   ro   rr   rs   rt   rv   rn   r   r    r   r   <module>r      sw    
    1)#X&
%IX('T+\/d$$*ZIX)X2.2r   