turbo-editors/turbo-corepublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

create.go · 33 lines · 951 BGo Blame HistoryRaw
🛟 Updated. 28d5985 k33g 4h ago1package tools
2
3import (
4 "fmt"
5
6 "codeberg.org/turbo-editors/turbo-core/profile"
7 "codeberg.org/turbo-editors/turbo-core/projectfile"
8)
9
10// Create writes a starter tools file for a project and returns its path.
11//
12// A project that already has one gives ErrExists and is left untouched: a file
13// somebody has been editing is never overwritten by a menu item.
14//
15// The file written is the profile's Templates.Tools, which is where the
16// commands themselves live: `go build ./...` for one editor, `cargo build` for
17// another.
18//
19// path, err := tools.Create(p, ".")
20// if errors.Is(err, tools.ErrExists) {
21// // already there; open it instead
22// }
23func Create(p profile.Profile, projectDir string) (string, error) {
24 path := Path(p, projectDir)
25 if Exists(p, projectDir) {
26 return path, fmt.Errorf("%w: %s", ErrExists, path)
27 }
28
29 if err := projectfile.Write(path, []byte(p.Templates.Tools)); err != nil {
30 return path, err
31 }
32 return path, nil
33}