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.

🛟 Updated. 28d5985 · on main · k33g · 4h ago
create.go · 33 lines · 951 BGo Blame HistoryRaw
 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"

	"codeberg.org/turbo-editors/turbo-core/profile"
	"codeberg.org/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
}