GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — func/cmd/completion_util.go at main · stackbuilders/func Expand file tree/ Copy pathcompletion_util.goMore file actions 213 lines (180 loc) · 4.84 KB / Copy pathcompletion_util.goFile metadata and controls213 lines (180 loc) · 4.84 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 package cmd import ( "encoding/json" "fmt" "os" "os/user" "path" "strings" "github.com/spf13/cobra" fn "knative.dev/func/pkg/functions" "knative.dev/func/pkg/k8s" "knative.dev/func/pkg/keda" "knative.dev/func/pkg/knative" ) func CompleteFunctionList(cmd *cobra.Command, args []string, toComplete string) (strings []string, directive cobra.ShellCompDirective) { kc := k8s.NewClient(k8s.GetClientConfig()) listers := []fn.Lister{ knative.NewLister(kc, false), k8s.NewLister(kc, false), } items := []fn.ListItem{} for _, lister := range listers { list, err := lister.List(cmd.Context(), "") if err != nil { directive = cobra.ShellCompDirectiveError return } items = append(items, list...) } for _, item := range items { strings = append(strings, item.Name) } directive = cobra.ShellCompDirectiveDefault return } func CompleteRuntimeList(cmd *cobra.Command, args []string, toComplete string, client *fn.Client) (matches []string, directive cobra.ShellCompDirective) { runtimes, err := client.Runtimes() if err != nil { fmt.Fprintf(os.Stderr, "error listing runtimes for flag completion: %v", err) return } for _, runtime := range runtimes { if strings.HasPrefix(runtime, toComplete) { matches = append(matches, runtime) } } return } func CompleteTemplateList(cmd *cobra.Command, args []string, toComplete string, client *fn.Client) (matches []string, directive cobra.ShellCompDirective) { directive = cobra.ShellCompDirectiveError lang, err := cmd.Flags().GetString("language") if err != nil { fmt.Fprintf(os.Stderr, "cannot list templates: %v", err) return } if lang == "" { fmt.Fprintln(os.Stderr, "cannot list templates: language not specified") return } templates, err := client.Templates().List(lang) if err != nil { fmt.Fprintf(os.Stderr, "cannot list templates: %v", err) return } directive = cobra.ShellCompDirectiveDefault for _, t := range templates { if strings.HasPrefix(t, toComplete) { matches = append(matches, t) } } return } func CompleteOutputFormatList(cmd *cobra.Command, args []string, toComplete string) (strings []string, directive cobra.ShellCompDirective) { directive = cobra.ShellCompDirectiveDefault strings = []string{"plain", "yaml", "json"} return } func CompleteRegistryList(cmd *cobra.Command, args []string, toComplete string) (strings []string, directive cobra.ShellCompDirective) { directive = cobra.ShellCompDirectiveError u, err := user.Current() if err != nil { return } file, err := os.Open(path.Join(u.HomeDir, ".docker", "config.json")) if err != nil { return } decoder := json.NewDecoder(file) var data map[string]interface{} err = decoder.Decode(&data) if err != nil { return } auth, ok := data["auths"].(map[string]interface{}) if !ok { return } strings = make([]string, len(auth)) for reg := range auth { strings = append(strings, reg) } directive = cobra.ShellCompDirectiveDefault return } func CompleteBuilderImageList(cmd *cobra.Command, args []string, complete string) (builderImages []string, directive cobra.ShellCompDirective) { directive = cobra.ShellCompDirectiveError var ( err error path string f fn.Function ) path, err = cmd.Flags().GetString("path") if err != nil { return } f, err = fn.NewFunction(path) if err != nil { return } builderImages = make([]string, 0, len(f.Build.BuilderImages)) for name := range f.Build.BuilderImages { if len(complete) == 0 { builderImages = append(builderImages, name) continue } if strings.HasPrefix(name, complete) { builderImages = append(builderImages, name) } } directive = cobra.ShellCompDirectiveNoFileComp return } func CompleteBuilderList(cmd *cobra.Command, args []string, complete string) (matches []string, d cobra.ShellCompDirective) { d = cobra.ShellCompDirectiveNoFileComp matches = []string{} if len(complete) == 0 { matches = KnownBuilders() return } for _, b := range KnownBuilders() { if strings.HasPrefix(b, complete) { matches = append(matches, b) } } return } func CompleteDeployerList(cmd *cobra.Command, args []string, complete string) (matches []string, d cobra.ShellCompDirective) { deployers := []string{ knative.KnativeDeployerName, k8s.KubernetesDeployerName, keda.KedaDeployerName, } d = cobra.ShellCompDirectiveNoFileComp matches = []string{} if len(complete) == 0 { matches = deployers return } for _, b := range deployers { if strings.HasPrefix(b, complete) { matches = append(matches, b) } } return } func CompleteExposeList(cmd *cobra.Command, args []string, complete string) (matches []string, d cobra.ShellCompDirective) { values := fn.ExposeModes d = cobra.ShellCompDirectiveNoFileComp matches = []string{} if len(complete) == 0 { matches = values return } for _, v := range values { if strings.HasPrefix(v, complete) { matches = append(matches, v) } } return } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |