Documentation
¶
Index ¶
- func NewCompletionCommand(root *cli.CLI) *cli.CLI
- type CommandCompletion
- type Completion
- type CompletionFunc
- type CompletionItem
- type CompletionManager
- func (cm *CompletionManager) Complete(args []string, toComplete string) []string
- func (cm *CompletionManager) CompleteWithDesc(args []string, toComplete string) []CompletionItem
- func (cm *CompletionManager) GenerateBashCompletion(w io.Writer, cmdName string) error
- func (cm *CompletionManager) GenerateCompletion(shell string, cname ...string) error
- func (cm *CompletionManager) GenerateFishCompletion(w io.Writer, cmdName string) error
- func (cm *CompletionManager) GenerateZshCompletion(w io.Writer, cmdName string) error
- func (cm *CompletionManager) HandleCompletion(args []string) error
- func (cm *CompletionManager) RegisterCompletion(cli *cli.CLI, flagName string, completion Completion)
- func (cm *CompletionManager) RegisterCustomCompletion(cli *cli.CLI, flagName string, fn CompletionFunc)
- func (cm *CompletionManager) RegisterCustomCompletionPrefixMatches(cli *cli.CLI, flagName string, completionItems any)
- func (cm *CompletionManager) RegisterDirectoryCompletion(cli *cli.CLI, flagName string)
- func (cm *CompletionManager) RegisterFileCompletion(cli *cli.CLI, flagName string, extensions ...string)
- type CompletionType
- type CustomCompletion
- type FileCompletion
- type FlagCompletion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CommandCompletion ¶
type CommandCompletion struct {
// contains filtered or unexported fields
}
CommandCompletion 命令补全
func NewCommandCompletion ¶
func NewCommandCompletion(cli *cli.CLI) *CommandCompletion
NewCommandCompletion 创建命令补全
func (*CommandCompletion) Complete ¶
func (c *CommandCompletion) Complete(args []string, toComplete string) []string
func (*CommandCompletion) CompleteWithDesc ¶
func (c *CommandCompletion) CompleteWithDesc(args []string, toComplete string) []CompletionItem
func (*CommandCompletion) GetType ¶
func (c *CommandCompletion) GetType() CompletionType
type Completion ¶
type Completion interface {
Complete(args []string, toComplete string) []string
CompleteWithDesc(args []string, toComplete string) []CompletionItem
GetType() CompletionType
}
Completion 补全接口
type CompletionFunc ¶
type CompletionFunc any
CompletionFunc 自定义补全函数 支持签名: func(string) []string 或 func(string) []CompletionItem
type CompletionItem ¶
CompletionItem 补全项
type CompletionManager ¶
type CompletionManager struct {
// contains filtered or unexported fields
}
CompletionManager 补全管理器
func New ¶
func New(root *cli.CLI) *CompletionManager
New 创建并初始化补全管理器 自动从 FlagSet.Item 读取 FlagItem 并生成补全 注册隐藏的 __complete 命令处理补全请求
func NewCompletionManager ¶
func NewCompletionManager(cli *cli.CLI) *CompletionManager
NewCompletionManager 创建补全管理器
func (*CompletionManager) Complete ¶
func (cm *CompletionManager) Complete(args []string, toComplete string) []string
Complete 执行补全
func (*CompletionManager) CompleteWithDesc ¶
func (cm *CompletionManager) CompleteWithDesc(args []string, toComplete string) []CompletionItem
CompleteWithDesc 带描述补全
func (*CompletionManager) GenerateBashCompletion ¶
func (cm *CompletionManager) GenerateBashCompletion(w io.Writer, cmdName string) error
GenerateBashCompletion 生成 Bash 补全脚本
func (*CompletionManager) GenerateCompletion ¶
func (cm *CompletionManager) GenerateCompletion(shell string, cname ...string) error
GenerateCompletion 生成补全脚本并输出到 stdout shell: 支持 "bash", "zsh", "fish" cname: 可选的命令名称,默认使用可执行文件名
func (*CompletionManager) GenerateFishCompletion ¶
func (cm *CompletionManager) GenerateFishCompletion(w io.Writer, cmdName string) error
GenerateFishCompletion 生成 Fish 补全脚本(支持描述)
func (*CompletionManager) GenerateZshCompletion ¶
func (cm *CompletionManager) GenerateZshCompletion(w io.Writer, cmdName string) error
GenerateZshCompletion 生成 Zsh 补全脚本(支持描述)
func (*CompletionManager) HandleCompletion ¶
func (cm *CompletionManager) HandleCompletion(args []string) error
HandleCompletion 处理补全请求
func (*CompletionManager) RegisterCompletion ¶
func (cm *CompletionManager) RegisterCompletion(cli *cli.CLI, flagName string, completion Completion)
RegisterCompletion 注册补全(可覆盖自动生成的补全)
func (*CompletionManager) RegisterCustomCompletion ¶
func (cm *CompletionManager) RegisterCustomCompletion(cli *cli.CLI, flagName string, fn CompletionFunc)
RegisterCustomCompletion 注册自定义补全
func (*CompletionManager) RegisterCustomCompletionPrefixMatches ¶
func (cm *CompletionManager) RegisterCustomCompletionPrefixMatches(cli *cli.CLI, flagName string, completionItems any)
RegisterCustomCompletionPrefixMatches 注册前缀匹配补全
func (*CompletionManager) RegisterDirectoryCompletion ¶
func (cm *CompletionManager) RegisterDirectoryCompletion(cli *cli.CLI, flagName string)
RegisterDirectoryCompletion 注册目录补全
func (*CompletionManager) RegisterFileCompletion ¶
func (cm *CompletionManager) RegisterFileCompletion(cli *cli.CLI, flagName string, extensions ...string)
RegisterFileCompletion 注册文件补全
type CompletionType ¶
type CompletionType int
CompletionType 补全类型
const ( CompletionTypeCommand CompletionType = iota CompletionTypeFlag CompletionTypeFile CompletionTypeDirectory CompletionTypeCustom )
type CustomCompletion ¶
type CustomCompletion struct {
// contains filtered or unexported fields
}
CustomCompletion 自定义补全
func NewCustomCompletion ¶
func NewCustomCompletion(fn CompletionFunc) *CustomCompletion
NewCustomCompletion 创建自定义补全
func (*CustomCompletion) Complete ¶
func (c *CustomCompletion) Complete(args []string, toComplete string) []string
func (*CustomCompletion) CompleteWithDesc ¶
func (c *CustomCompletion) CompleteWithDesc(args []string, toComplete string) []CompletionItem
func (*CustomCompletion) GetType ¶
func (c *CustomCompletion) GetType() CompletionType
type FileCompletion ¶
type FileCompletion struct {
// contains filtered or unexported fields
}
FileCompletion 文件路径补全
func NewDirectoryCompletion ¶
func NewDirectoryCompletion() *FileCompletion
NewDirectoryCompletion 创建目录补全
func NewFileCompletion ¶
func NewFileCompletion(extensions ...string) *FileCompletion
NewFileCompletion 创建文件补全
func (*FileCompletion) Complete ¶
func (f *FileCompletion) Complete(args []string, toComplete string) []string
func (*FileCompletion) CompleteWithDesc ¶
func (f *FileCompletion) CompleteWithDesc(args []string, toComplete string) []CompletionItem
func (*FileCompletion) GetType ¶
func (f *FileCompletion) GetType() CompletionType
type FlagCompletion ¶
type FlagCompletion struct {
// contains filtered or unexported fields
}
FlagCompletion flag 补全
func NewFlagCompletion ¶
func NewFlagCompletion(flagSet *cli.FlagSet) *FlagCompletion
NewFlagCompletion 创建参数补全
func (*FlagCompletion) Complete ¶
func (f *FlagCompletion) Complete(args []string, toComplete string) []string
func (*FlagCompletion) CompleteWithDesc ¶
func (f *FlagCompletion) CompleteWithDesc(args []string, toComplete string) []CompletionItem
func (*FlagCompletion) GetType ¶
func (f *FlagCompletion) GetType() CompletionType