-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathinfo.go
More file actions
126 lines (107 loc) · 3.23 KB
/
info.go
File metadata and controls
126 lines (107 loc) · 3.23 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
package cmd
import (
"context"
"fmt"
"os"
"strconv"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/salt/cli/printer"
stencilv1beta1 "github.com/raystack/stencil/proto/raystack/stencil/v1beta1"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func infoSchemaCmd(cdk *CDK) *cobra.Command {
var namespace string
cmd := &cobra.Command{
Use: "info <id>",
Short: "View schema information",
Long: "Display the information about a schema.",
Args: cobra.ExactArgs(1),
Example: heredoc.Doc(`
$ stencil schema info events -n raystack
`),
RunE: func(cmd *cobra.Command, args []string) error {
spinner := printer.Spin("")
defer spinner.Stop()
client, cancel, err := createClient(cmd, cdk)
if err != nil {
return err
}
defer cancel()
req := stencilv1beta1.GetSchemaMetadataRequest{
NamespaceId: namespace,
SchemaId: args[0],
}
info, err := client.GetSchemaMetadata(cmd.Context(), &req)
spinner.Stop()
if err != nil {
errStatus, _ := status.FromError(err)
if codes.NotFound == errStatus.Code() {
fmt.Printf("%s Schema with id '%s' not found.\n", printer.Red(printer.Icon("failure")), args[0])
return nil
}
return err
}
fmt.Printf("\n%s\n", printer.Blue(args[0]))
fmt.Printf("\n%s\n\n", printer.Grey("No description provided"))
fmt.Printf("%s \t %s \n", printer.Grey("Namespace:"), namespace)
fmt.Printf("%s \t %s \n", printer.Grey("Format:"), dict[info.GetFormat().String()])
fmt.Printf("%s \t %s \n", printer.Grey("Compatibility:"), dict[info.GetCompatibility().String()])
fmt.Printf("%s \t %s \n\n", printer.Grey("Authority:"), dict[info.GetAuthority()])
return nil
},
}
cmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Provide schema namespace")
cmd.MarkFlagRequired("namespace")
return cmd
}
func versionSchemaCmd(cdk *CDK) *cobra.Command {
var namespaceID string
var req stencilv1beta1.ListVersionsRequest
cmd := &cobra.Command{
Use: "version",
Short: "View versions of a schema",
Args: cobra.ExactArgs(1),
Example: heredoc.Doc(`
$ stencil schema version booking -n raystack
`),
RunE: func(cmd *cobra.Command, args []string) error {
spinner := printer.Spin("")
defer spinner.Stop()
client, cancel, err := createClient(cmd, cdk)
if err != nil {
return err
}
defer cancel()
schemaID := args[0]
req.NamespaceId = namespaceID
req.SchemaId = schemaID
res, err := client.ListVersions(context.Background(), &req)
if err != nil {
return err
}
versions := res.GetVersions()
spinner.Stop()
if len(versions) == 0 {
fmt.Printf("No version found for %s in %s", schemaID, namespaceID)
return nil
}
report := [][]string{}
report = append(report, []string{"VERSION", "CREATED", "MESSAGE"})
for _, v := range versions {
report = append(report, []string{
printer.Greenf("#%v", strconv.FormatInt(int64(v), 10)),
"-",
"-",
})
}
fmt.Printf("\nShowing %[1]d of %[1]d versions for %s\n \n", len(versions), schemaID)
printer.Table(os.Stdout, report)
return nil
},
}
cmd.Flags().StringVarP(&namespaceID, "namespace", "n", "", "parent namespace ID")
cmd.MarkFlagRequired("namespace")
return cmd
}