package acp import ( "fmt" "rickub.com/turbo-editors/turbo-core/profile" "rickub.com/turbo-editors/turbo-core/projectfile" ) // template returns the starter file: the profile's Templates.Agents with the // editor's own project directory and the user's own agents path filled into // it, in that order. func template(p profile.Profile) string { return fmt.Sprintf(p.Templates.Agents, p.ProjectDir(), userPathComment(p)) } // userPathComment returns the user's agents path for the template's comment, // or a plain description when there is nowhere to put one. func userPathComment(p profile.Profile) string { if path := UserPath(p); path != "" { return path } return "(no configuration directory on this system)" } // Create writes a starter agents 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.Agents, which is where the // example belongs — the agent a Go project reaches for is not necessarily the // one a Rust project does, and the path in its arguments is the editor's own // project directory. // // path, err := acp.Create(p, ".") // if errors.Is(err, acp.ErrExists) { // // already there; open it instead // } func Create(p profile.Profile, projectDir string) (string, error) { path := ProjectPath(p, projectDir) if Exists(p, projectDir) { return path, fmt.Errorf("%w: %s", ErrExists, path) } if err := projectfile.Write(path, []byte(template(p))); err != nil { return path, err } return path, nil }