-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathconfig_init.go
51 lines (41 loc) · 1.29 KB
/
config_init.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
49
50
51
// Copyright (c) 2022 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.
package cmd
import (
"fmt"
"github.com/gitpod-io/gitpod/installer/pkg/config"
"github.com/spf13/cobra"
)
var configInitOpts struct {
OverwriteConfig bool
}
// configInitCmd represents the validate command
var configInitCmd = &cobra.Command{
Use: "init",
Short: "Create a base config file",
Long: `Create a base config file
This file contains all the credentials to install a Gitpod instance and
be saved to a repository.`,
Example: ` # Save config to config.yaml.
gitpod-installer config init -c ./gitpod.config.yaml`,
RunE: func(cmd *cobra.Command, args []string) error {
// Check file isn't present
exists, err := configFileExists()
if err != nil {
return err
}
if *exists && !configInitOpts.OverwriteConfig {
return fmt.Errorf("file %s exists - to overwrite add --overwrite flag", configOpts.ConfigFile)
}
cfg, err := config.NewDefaultConfig()
if err != nil {
return err
}
return saveConfigFile(cfg)
},
}
func init() {
configCmd.AddCommand(configInitCmd)
configInitCmd.Flags().BoolVar(&configInitOpts.OverwriteConfig, "overwrite", false, "overwrite config file if it exists")
}