in action/config/config.go [71:112]
func createYMLFile(path string) error {
// Check if the path exists
//if _, err := os.Stat(path); os.IsNotExist(err) {
// return fmt.Errorf("path does not exist: %s", path)
//}
// Check if the file already exists
ymlFilePath := "config.yml"
if _, err := os.Stat(ymlFilePath); err == nil {
fmt.Println("Config file already exists!")
return nil
}
// Create a sample config object
config := createSampleConfig()
// Marshal the config object into YAML format
data, err := yaml.Marshal(&config)
if err != nil {
log.Fatalf("Failed to marshal config to YAML: %v", err)
}
// Write the YAML data to a file
file, err := os.Create("config.yml")
if err != nil {
log.Fatalf("Failed to create YAML config: %v", err)
}
defer func() {
if err := file.Close(); err != nil {
log.Fatalf("Failed to close config file: %v", err)
}
}()
_, err = file.Write(data)
if err != nil {
log.Fatalf("Failed to write to YAML config: %v", err)
}
fmt.Println("Config created successfully!")
// Update the path variable
Path = path
return nil
}