跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

completion.go

78 行 · 2.1 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package main
5
6import (
7 "maps"
8 "net"
9 "slices"
10 "strings"
11
12 "github.com/spf13/cobra"
13
14 "github.com/lima-vm/lima/v2/pkg/networks"
15 "github.com/lima-vm/lima/v2/pkg/store"
16 "github.com/lima-vm/lima/v2/pkg/templatestore"
17)
18
19func bashCompleteInstanceNames(_ *cobra.Command) ([]string, cobra.ShellCompDirective) {
20 instances, err := store.Instances()
21 if err != nil {
22 return nil, cobra.ShellCompDirectiveDefault
23 }
24 return instances, cobra.ShellCompDirectiveNoFileComp
25}
26
27func bashCompleteTemplateNames(_ *cobra.Command, toComplete string) ([]string, cobra.ShellCompDirective) {
28 var comp []string
29 if templates, err := templatestore.Templates(); err == nil {
30 for _, f := range templates {
31 name := "template:" + f.Name
32 if !strings.HasPrefix(name, toComplete) {
33 continue
34 }
35 if len(toComplete) == len(name) {
36 comp = append(comp, name)
37 continue
38 }
39
40 // Skip private snippets (beginning with '_') from completion.
41 if (name[len(toComplete)-1] == '/') && (name[len(toComplete)] == '_') {
42 continue
43 }
44
45 comp = append(comp, name)
46 }
47 }
48 return comp, cobra.ShellCompDirectiveDefault
49}
50
51func bashCompleteDiskNames(_ *cobra.Command) ([]string, cobra.ShellCompDirective) {
52 disks, err := store.Disks()
53 if err != nil {
54 return nil, cobra.ShellCompDirectiveDefault
55 }
56 return disks, cobra.ShellCompDirectiveNoFileComp
57}
58
59func bashCompleteNetworkNames(_ *cobra.Command) ([]string, cobra.ShellCompDirective) {
60 config, err := networks.LoadConfig()
61 if err != nil {
62 return nil, cobra.ShellCompDirectiveDefault
63 }
64 networks := slices.Sorted(maps.Keys(config.Networks))
65 return networks, cobra.ShellCompDirectiveNoFileComp
66}
67
68func bashFlagCompleteNetworkInterfaceNames(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
69 intf, err := net.Interfaces()
70 if err != nil {
71 return nil, cobra.ShellCompDirectiveDefault
72 }
73 var intfNames []string
74 for _, f := range intf {
75 intfNames = append(intfNames, f.Name)
76 }
77 return intfNames, cobra.ShellCompDirectiveNoFileComp
78}