-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathlist.go
More file actions
82 lines (70 loc) · 1.91 KB
/
Copy pathlist.go
File metadata and controls
82 lines (70 loc) · 1.91 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
package cmd
import (
"context"
"fmt"
"os"
"connectrpc.com/connect"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/salt/cli/printer"
stencilv1beta1 "github.com/raystack/stencil/gen/raystack/stencil/v1beta1"
"github.com/spf13/cobra"
)
func listSchemaCmd(cdk *CDK) *cobra.Command {
var namespace string
cmd := &cobra.Command{
Use: "list",
Short: "List all schemas",
Long: heredoc.Doc(`
List schemas in a namespace.
`),
Args: cobra.ExactArgs(0),
Example: heredoc.Doc(`
$ stencil schema list -n raystack
`),
RunE: func(cmd *cobra.Command, args []string) error {
spinner := printer.Spin("")
defer spinner.Stop()
client, err := createClient(cmd, cdk)
if err != nil {
return err
}
res, err := client.ListSchemas(context.Background(), connect.NewRequest(&stencilv1beta1.ListSchemasRequest{Id: namespace}))
if err != nil {
return err
}
schemas := res.Msg.GetSchemas()
// TODO(Ravi): List schemas should also handle namespace not found
if len(schemas) == 0 {
spinner.Stop()
fmt.Printf("No schema found in namespace %s\n", namespace)
return nil
}
report := [][]string{}
index := 1
report = append(report, []string{
printer.Bold("INDEX"),
printer.Bold("NAME"),
printer.Bold("FORMAT"),
printer.Bold("COMPATIBILITY"),
printer.Bold("AUTHORITY"),
})
for _, s := range schemas {
c := s.GetCompatibility().String()
f := s.GetFormat().String()
a := s.GetAuthority()
if a == "" {
a = "-"
}
report = append(report, []string{printer.Greenf("#%d", index), s.GetName(), dict[f], dict[c], a})
index++
}
spinner.Stop()
fmt.Printf("\nShowing %d of %d schemas in %s\n\n", len(schemas), len(schemas), namespace)
printer.Table(os.Stdout, report)
return nil
},
}
cmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace ID")
_ = cmd.MarkFlagRequired("namespace")
return cmd
}