turbo-editors/turbo-corepublic Fork 0
v1.0.1
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 · 50 lines · 1.6 KBGo Blame HistoryRaw
🛟 Updated. 28d5985 k33g 15h ago1package acp
2
3import (
4 "fmt"
5
📦 Turbo Core f3ade8d k33g 8h ago6 "rickub.com/turbo-editors/turbo-core/profile"
7 "rickub.com/turbo-editors/turbo-core/projectfile"
🛟 Updated. 28d5985 k33g 15h ago8)
9
10// template returns the starter file: the profile's Templates.Agents with the
11// editor's own project directory and the user's own agents path filled into
12// it, in that order.
13func template(p profile.Profile) string {
14 return fmt.Sprintf(p.Templates.Agents, p.ProjectDir(), userPathComment(p))
15}
16
17// userPathComment returns the user's agents path for the template's comment,
18// or a plain description when there is nowhere to put one.
19func userPathComment(p profile.Profile) string {
20 if path := UserPath(p); path != "" {
21 return path
22 }
23 return "(no configuration directory on this system)"
24}
25
26// Create writes a starter agents file for a project and returns its path.
27//
28// A project that already has one gives ErrExists and is left untouched: a file
29// somebody has been editing is never overwritten by a menu item.
30//
31// The file written is the profile's Templates.Agents, which is where the
32// example belongs — the agent a Go project reaches for is not necessarily the
33// one a Rust project does, and the path in its arguments is the editor's own
34// project directory.
35//
36// path, err := acp.Create(p, ".")
37// if errors.Is(err, acp.ErrExists) {
38// // already there; open it instead
39// }
40func Create(p profile.Profile, projectDir string) (string, error) {
41 path := ProjectPath(p, projectDir)
42 if Exists(p, projectDir) {
43 return path, fmt.Errorf("%w: %s", ErrExists, path)
44 }
45
46 if err := projectfile.Write(path, []byte(template(p))); err != nil {
47 return path, err
48 }
49 return path, nil
50}