Path: blob/main/components/image-builder-mk3/cmd/generate-config.go
2497 views
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34//go:generate sh -c "cd .. && CGO_ENABLED=0 go run main.go generate config > config-schema.json"56package cmd78import (9"encoding/json"10"fmt"11"github.com/alecthomas/jsonschema"12"github.com/gitpod-io/gitpod/image-builder/api/config"13"github.com/spf13/cobra"14)1516// generateCmd represents the generate command17var generateCmd = &cobra.Command{18Use: "generate <type>",19Short: "Generate Typescript/JSON schema for parts of this application",20Args: cobra.ExactArgs(1),21}2223func init() {24rootCmd.AddCommand(generateCmd)25}2627var generateConfigCmd = &cobra.Command{28Use: "config",29Short: "Generates JSON schema for the configuration",3031Run: func(cmd *cobra.Command, args []string) {32schema := jsonschema.Reflect(&config.ServiceConfig{})33schema.Title = "image-builder config schema - generated using img generate config"34out, err := json.MarshalIndent(schema, "", " ")35if err != nil {36panic(err)37}38fmt.Print(string(out))39},40}4142func init() {43generateCmd.AddCommand(generateConfigCmd)44}454647