-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathgenerate-config.go
45 lines (37 loc) · 1.17 KB
/
generate-config.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
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
//go:generate sh -c "cd .. && CGO_ENABLED=0 go run main.go generate config > config-schema.json"
package cmd
import (
"encoding/json"
"fmt"
"github.com/alecthomas/jsonschema"
"github.com/gitpod-io/gitpod/image-builder/api/config"
"github.com/spf13/cobra"
)
// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "generate <type>",
Short: "Generate Typescript/JSON schema for parts of this application",
Args: cobra.ExactArgs(1),
}
func init() {
rootCmd.AddCommand(generateCmd)
}
var generateConfigCmd = &cobra.Command{
Use: "config",
Short: "Generates JSON schema for the configuration",
Run: func(cmd *cobra.Command, args []string) {
schema := jsonschema.Reflect(&config.ServiceConfig{})
schema.Title = "image-builder config schema - generated using img generate config"
out, err := json.MarshalIndent(schema, "", " ")
if err != nil {
panic(err)
}
fmt.Print(string(out))
},
}
func init() {
generateCmd.AddCommand(generateConfigCmd)
}