填写 --<option>:<file> 和 --<option>:<possible values> 形式的选项

Completing options of the form --<option>:<file> and --<option>:<possible values>

我正在尝试为 fsharpi(F# 交互式)编写一个完成方法,它具有如下选项:

--use:<file>              Use the given file on startup as initial input
--debug:{full|pdbonly}    Specify debugging type: full, pdbonly. ('full' is the default and enables attaching a debugger to a running program).
--warn:<n>                Set a warning level (0-5)

我猜这必须像 sub-commands 一样用 $state 来处理,但是文档是单一的并且语言不是很详细,所以通过实验和拼接不同的示例,我一无所获。

这个问题的解决方案也适用于 aspell,它使用等号而不是冒号,例如

--conf=<str>              main configuration file

这是最常见的补全形式之一,_arguments 可以轻松处理。请注意,选项中的文字冒号可以用反斜杠引用。这是代码示例:

#compdef command

arguments=(
    '--use\:-:initial input file:_files'
    '--debug\:-:debugging type:(full pbonly)'
    '--warn\:-:warning level:(0 1 2 3 4 5)'
)

_arguments -S $arguments[@]

参考:_arguments in official documentation.