-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtemplate.go
43 lines (35 loc) · 1.02 KB
/
template.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
package cmd
import (
"github.com/speakeasy-api/speakeasy/internal/template"
"github.com/spf13/cobra"
)
var templateCmd = &cobra.Command{
Use: "template",
Short: "executes your template to render an OpenAPI file.",
Args: cobra.NoArgs,
RunE: runTemplate,
}
func templateInit() {
templateCmd.Flags().StringP("template", "t", "", "template file")
templateCmd.MarkFlagRequired("template")
templateCmd.Flags().StringP("values", "v", "", "values file")
templateCmd.MarkFlagRequired("values")
templateCmd.Flags().StringP("out", "o", "", "output location")
templateCmd.MarkFlagRequired("out")
rootCmd.AddCommand(templateCmd)
}
func runTemplate(cmd *cobra.Command, args []string) error {
templateLocation, err := cmd.Flags().GetString("template")
if err != nil {
return err
}
valuesLocation, err := cmd.Flags().GetString("values")
if err != nil {
return err
}
outLocation, err := cmd.Flags().GetString("out")
if err != nil {
return err
}
return template.Execute(templateLocation, valuesLocation, outLocation)
}