/
completion.go
115 lines (110 loc) · 3.29 KB
/
completion.go
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
package cmd
import (
metalgo "github.com/metal-stack/metal-go"
"github.com/spf13/cobra"
)
func imageListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.ImageList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, i := range resp.Image {
names = append(names, *i.ID)
}
return names, cobra.ShellCompDirectiveDefault
}
func partitionListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.PartitionList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, p := range resp.Partition {
names = append(names, *p.ID)
}
return names, cobra.ShellCompDirectiveDefault
}
func sizeListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.SizeList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, s := range resp.Size {
names = append(names, *s.ID)
}
return names, cobra.ShellCompDirectiveDefault
}
func filesystemLayoutListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.FilesystemLayoutList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, s := range resp {
names = append(names, *s.ID)
}
return names, cobra.ShellCompDirectiveDefault
}
func machineListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.MachineList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, m := range resp.Machines {
names = append(names, *m.ID)
}
return names, cobra.ShellCompDirectiveDefault
}
func networkListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.NetworkList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, n := range resp.Networks {
names = append(names, *n.ID)
}
return names, cobra.ShellCompDirectiveDefault
}
func ipListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.IPList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, i := range resp.IPs {
names = append(names, *i.Ipaddress)
}
return names, cobra.ShellCompDirectiveDefault
}
func projectListCompletion(driver *metalgo.Driver) ([]string, cobra.ShellCompDirective) {
resp, err := driver.ProjectList()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, p := range resp.Project {
names = append(names, p.Meta.ID)
}
return names, cobra.ShellCompDirectiveDefault
}
func contextListCompletion() ([]string, cobra.ShellCompDirective) {
ctxs, err := getContexts()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for name := range ctxs.Contexts {
names = append(names, name)
}
return names, cobra.ShellCompDirectiveDefault
}
func outputFormatListCompletion() ([]string, cobra.ShellCompDirective) {
return []string{"table", "wide", "markdown", "json", "yaml", "template"}, cobra.ShellCompDirectiveDefault
}
func outputOrderListCompletion() ([]string, cobra.ShellCompDirective) {
return []string{"size", "id", "status", "event", "when", "partition", "project"}, cobra.ShellCompDirectiveDefault
}