-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathget.go
More file actions
100 lines (86 loc) · 2.48 KB
/
get.go
File metadata and controls
100 lines (86 loc) · 2.48 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
package cmd
import (
"context"
"errors"
"fmt"
"github.com/gojek/feast/cli/feast/pkg/printer"
"github.com/gojek/feast/protos/generated/go/feast/core"
"github.com/spf13/cobra"
)
// listCmd represents the list command
var getCmd = &cobra.Command{
Use: "get [resource] [id]",
Short: "Get and print the details of the desired resource.",
Long: `Get and print the details of the desired resource.
Valid resources include:
- entity
- feature
- job
Examples:
- feast get entity myentity`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
}
if len(args) != 2 {
return errors.New("invalid number of arguments for list command")
}
initConn()
err := get(args[0], args[1])
if err != nil {
return fmt.Errorf("failed to list %s: %v", args[0], err)
}
return nil
},
}
func init() {
rootCmd.AddCommand(getCmd)
}
func get(resource string, id string) error {
ctx := context.Background()
switch resource {
case "feature":
return getFeature(ctx, core.NewUIServiceClient(coreConn), id)
case "entity":
return getEntity(ctx, core.NewUIServiceClient(coreConn), id)
case "storage":
return getStorage(ctx, core.NewUIServiceClient(coreConn), id)
case "job":
return getJob(ctx, core.NewJobServiceClient(coreConn), id)
default:
return fmt.Errorf("invalid resource %s: please choose one of [features, entities, storage, jobs]", resource)
}
}
func getFeature(ctx context.Context, cli core.UIServiceClient, id string) error {
response, err := cli.GetFeature(ctx, &core.UIServiceTypes_GetFeatureRequest{Id: id})
if err != nil {
return err
}
printer.PrintFeatureDetail(response.GetFeature())
return nil
}
func getEntity(ctx context.Context, cli core.UIServiceClient, id string) error {
response, err := cli.GetEntity(ctx, &core.UIServiceTypes_GetEntityRequest{Id: id})
if err != nil {
return err
}
printer.PrintEntityDetail(response.GetEntity())
return nil
}
// This function is deprecated, and may be removed in subsequent versions.
func getStorage(ctx context.Context, cli core.UIServiceClient, id string) error {
response, err := cli.GetStorage(ctx, &core.UIServiceTypes_GetStorageRequest{Id: id})
if err != nil {
return err
}
printer.PrintStorageDetail(response.GetStorage())
return nil
}
func getJob(ctx context.Context, cli core.JobServiceClient, id string) error {
response, err := cli.GetJob(ctx, &core.JobServiceTypes_GetJobRequest{Id: id})
if err != nil {
return err
}
printer.PrintJobDetail(response.GetJob())
return nil
}