MCPcopy Create free account
hub / github.com/encoder-run/operator / ensureConfigExists

Function ensureConfigExists

cmd/cli/cmd/initializer.go:28–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26}
27
28func ensureConfigExists() {
29 // Check if the configuration directory exists
30 home, err := os.UserHomeDir()
31 cobra.CheckErr(err)
32 configDir := path.Join(home, ".encoder-run")
33 if _, err := os.Stat(configDir); os.IsNotExist(err) {
34 // Create the configuration directory
35 err = os.Mkdir(configDir, 0755)
36 if err != nil {
37 fmt.Printf("Error creating config directory: %v\n", err)
38 os.Exit(1)
39 }
40
41 // Create blank configuration file
42 configFile := path.Join(configDir, "config")
43 file, err := os.Create(configFile)
44 if err != nil {
45 fmt.Printf("Error creating config file: %v\n", err)
46 os.Exit(1)
47 }
48 defer file.Close()
49 }
50
51 // Ensure there is a configuration file present
52 if _, err := os.Stat(path.Join(configDir, "config")); os.IsNotExist(err) {
53 // Write a blank configuration file
54 viper.SetConfigFile(path.Join(configDir, "config"))
55 err = viper.WriteConfig()
56 if err != nil {
57 fmt.Printf("Error writing config: %v\n", err)
58 os.Exit(1)
59 }
60 }
61}
62
63func setupConfig() {
64 // OpenAI Token prompt

Callers 1

setupConfigFunction · 0.85

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected