MCPcopy Create free account
hub / github.com/celer-pkg/celer / Write

Method Write

configs/project.go:68–102  ·  view source on GitHub ↗
(platformPath string, override bool)

Source from the content-addressed store, hash-verified

66}
67
68func (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
104func (p Project) GetName() string {
105 return p.Name

Callers 1

CreateProjectMethod · 0.95

Calls 3

PathExistsFunction · 0.92
MkdirAllMethod · 0.80
WriteFileMethod · 0.80

Tested by

no test coverage detected