-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathget.go
More file actions
52 lines (44 loc) · 1012 Bytes
/
get.go
File metadata and controls
52 lines (44 loc) · 1012 Bytes
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
package cmd
import (
"context"
"errors"
"fmt"
pb "github.com/runconduit/conduit/controller/gen/public"
"github.com/spf13/cobra"
)
var getCmd = &cobra.Command{
Use: "get [flags] RESOURCE",
Short: "Display one or many mesh resources",
Long: `Display one or many mesh resources.
Valid resource types include:
* pods (aka pod, po)`,
RunE: func(cmd *cobra.Command, args []string) error {
switch len(args) {
case 1:
resourceType := args[0]
switch resourceType {
case "pod", "pods", "po":
client, err := newApiClient()
if err != nil {
return err
}
resp, err := client.ListPods(context.Background(), &pb.Empty{})
if err != nil {
return err
}
for _, pod := range resp.GetPods() {
fmt.Println(pod.Name)
}
default:
return errors.New("invalid resource type")
}
return nil
default:
return errors.New("please specify a resource type")
}
},
}
func init() {
RootCmd.AddCommand(getCmd)
addControlPlaneNetworkingArgs(getCmd)
}