Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/image-builder-mk3/cmd/generate-config.go
2497 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
//go:generate sh -c "cd .. && CGO_ENABLED=0 go run main.go generate config > config-schema.json"
6
7
package cmd
8
9
import (
10
"encoding/json"
11
"fmt"
12
"github.com/alecthomas/jsonschema"
13
"github.com/gitpod-io/gitpod/image-builder/api/config"
14
"github.com/spf13/cobra"
15
)
16
17
// generateCmd represents the generate command
18
var generateCmd = &cobra.Command{
19
Use: "generate <type>",
20
Short: "Generate Typescript/JSON schema for parts of this application",
21
Args: cobra.ExactArgs(1),
22
}
23
24
func init() {
25
rootCmd.AddCommand(generateCmd)
26
}
27
28
var generateConfigCmd = &cobra.Command{
29
Use: "config",
30
Short: "Generates JSON schema for the configuration",
31
32
Run: func(cmd *cobra.Command, args []string) {
33
schema := jsonschema.Reflect(&config.ServiceConfig{})
34
schema.Title = "image-builder config schema - generated using img generate config"
35
out, err := json.MarshalIndent(schema, "", " ")
36
if err != nil {
37
panic(err)
38
}
39
fmt.Print(string(out))
40
},
41
}
42
43
func init() {
44
generateCmd.AddCommand(generateConfigCmd)
45
}
46
47