/
wizard.go
48 lines (39 loc) · 1.1 KB
/
wizard.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
package cmd
import (
"log"
"os"
"github.com/getkin/kin-openapi/openapi3"
"github.com/mattn/go-isatty"
"github.com/spf13/cobra"
"github.com/kubeshop/kusk-gen/spec"
"github.com/kubeshop/kusk-gen/wizard"
"github.com/kubeshop/kusk-gen/wizard/prompt"
)
func init() {
var apiSpecPath string
wizardCmd := &cobra.Command{
Use: "wizard",
Short: "Connects to current Kubernetes cluster and lists available generators",
Run: func(cmd *cobra.Command, args []string) {
if isTTY := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd()); !isTTY {
log.Fatal("the wizard is only supported in an interactive context i.e. TTY")
}
// parse OpenAPI spec
apiSpec, err := spec.NewParser(openapi3.NewLoader()).Parse(apiSpecPath)
if err != nil {
log.Fatal(err)
}
wizard.Start(apiSpecPath, apiSpec, prompt.New())
},
}
// add common required flags
wizardCmd.Flags().StringVarP(
&apiSpecPath,
"in",
"i",
"",
"file path to api spec file to generate mappings from. e.g. --in apispec.yaml",
)
wizardCmd.MarkFlagRequired("in")
rootCmd.AddCommand(wizardCmd)
}