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
|
package tools
import (
"fmt"
"rickub.com/turbo-editors/turbo-core/profile"
"rickub.com/turbo-editors/turbo-core/projectfile"
)
// Create writes a starter tools file for a project and returns its path.
//
// A project that already has one gives ErrExists and is left untouched: a file
// somebody has been editing is never overwritten by a menu item.
//
// The file written is the profile's Templates.Tools, which is where the
// commands themselves live: `go build ./...` for one editor, `cargo build` for
// another.
//
// path, err := tools.Create(p, ".")
// if errors.Is(err, tools.ErrExists) {
// // already there; open it instead
// }
func Create(p profile.Profile, projectDir string) (string, error) {
path := Path(p, projectDir)
if Exists(p, projectDir) {
return path, fmt.Errorf("%w: %s", ErrExists, path)
}
if err := projectfile.Write(path, []byte(p.Templates.Tools)); err != nil {
return path, err
}
return path, nil
}
|