| 🛟 Updated. 28d5985 k33g 4h ago | 1 | package tools |
| 2 | |
| 3 | import ( |
| 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 | // } |
| 23 | func 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 | } |