(platformPath string, override bool)
| 66 | } |
| 67 | |
| 68 | func (p Project) Write(platformPath string, override bool) error { |
| 69 | if p.BuildType == "" { |
| 70 | p.BuildType = "Release" |
| 71 | } |
| 72 | if len(p.Ports) == 0 { |
| 73 | p.Ports = []string{} |
| 74 | } |
| 75 | if len(p.Vars) == 0 { |
| 76 | p.Vars = []string{} |
| 77 | } |
| 78 | if len(p.Envs) == 0 { |
| 79 | p.Envs = []string{} |
| 80 | } |
| 81 | if len(p.Macros) == 0 { |
| 82 | p.Macros = []string{} |
| 83 | } |
| 84 | |
| 85 | bytes, err := toml.Marshal(p) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | // Check if conf/projects/<project_name>.toml exists. |
| 91 | if fileio.PathExists(platformPath) && !override { |
| 92 | return fmt.Errorf("%s is already exists", platformPath) |
| 93 | } |
| 94 | |
| 95 | // Make sure the parent directory exists. |
| 96 | parentDir := filepath.Dir(platformPath) |
| 97 | if err := os.MkdirAll(parentDir, os.ModePerm); err != nil { |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | return os.WriteFile(platformPath, bytes, os.ModePerm) |
| 102 | } |
| 103 | |
| 104 | func (p Project) GetName() string { |
| 105 | return p.Name |
no test coverage detected