Documentation
¶
Overview ¶
Package runconfig models named run/debug configurations for a project — the equivalent of Qt Creator's "Run Settings", where one project owns several launch targets (run the app, debug it, run the package tests) and one of them is the active default.
A Config is a pure value: it says what to launch (Target), how (Mode), with which toolchain (KitName), what to build first (PreRun) and in which environment (Args / WorkDir / Env). It never launches anything itself — the IDE host turns a Config into a process. Store owns the named collection and its two invariants: names are unique, and at most one Config carries the Default flag.
Index ¶
- Constants
- Variables
- func Modes() []string
- func ParseEnv(lines []string) map[string]string
- func StorePath(projectDir string) string
- func ValidMode(mode string) bool
- type Config
- type Store
- func (s *Store) Add(c Config) error
- func (s *Store) Default() (Config, bool)
- func (s *Store) Get(name string) (Config, bool)
- func (s *Store) Len() int
- func (s *Store) List() []Config
- func (s *Store) Remove(name string) bool
- func (s *Store) Save(path string) error
- func (s *Store) SetDefault(name string) bool
- func (s *Store) Update(name string, c Config) error
Constants ¶
const ( ModeRun = "run" ModeDebug = "debug" ModeTest = "test" ModeBench = "bench" )
Launch modes. Mode selects which command shape the host builds for a configuration: run the target, run it under the debugger, run its tests, or run its benchmarks.
Variables ¶
var ( ErrEmptyName = errors.New("runconfig: configuration name is empty") ErrEmptyTarget = errors.New("runconfig: configuration target is empty") ErrInvalidMode = errors.New("runconfig: unknown launch mode") ErrDuplicateName = errors.New("runconfig: duplicate configuration name") ErrNotFound = errors.New("runconfig: configuration not found") )
Validation errors. Callers can match these with errors.Is.
Functions ¶
func Modes ¶
func Modes() []string
Modes returns the launch modes in UI order. Used by editors that cycle or list the mode field.
func ParseEnv ¶
ParseEnv is the inverse of EnvSlice: it turns "KEY=value" entries into a map. Blank entries are dropped, surrounding whitespace is trimmed, an entry with no '=' becomes a key with an empty value, and a repeated key keeps the last value. Returns nil when nothing survives.
Types ¶
type Config ¶
type Config struct {
Name string `json:"name"` // unique within a Store; shown in the configuration list
Target string `json:"target"` // package path ("." / "./cmd/app") or a single file
Args []string `json:"args,omitempty"` // command-line arguments passed to the target
WorkDir string `json:"workDir,omitempty"` // process working directory; empty means the project root
Env map[string]string `json:"env,omitempty"` // extra environment variables
Mode string `json:"mode,omitempty"` // one of the Mode* constants; empty means ModeRun
KitName string `json:"kit,omitempty"` // toolchain / kit to build and launch with; empty means the default kit
PreRun []string `json:"preRun,omitempty"` // task names to run before launching (e.g. a build task)
Default bool `json:"default,omitempty"` // the configuration launched when none is named
}
Config is one named launch configuration.
func (Config) Clone ¶
Clone deep-copies the configuration so the caller can mutate the result without touching the original's slices or map.
func (Config) EffectiveMode ¶
EffectiveMode returns Mode, substituting ModeRun when it is unset.
func (Config) EnvSlice ¶
EnvSlice returns Env as "KEY=value" entries — the form os/exec wants — sorted by key so callers get a stable order out of the map. Returns nil when Env is empty.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the ordered collection of a project's named configurations. It enforces two invariants on every mutation: names are unique (compared after trimming, case-sensitively), and at most one Config carries the Default flag.
The zero Store is an empty, usable store.
func Load ¶
Load reads a store previously written by Save. Every entry is replayed through Add, so a hand-edited file that violates validation or repeats a name is reported instead of silently loaded half-broken.
func (*Store) Add ¶
Add appends c. It fails with a validation error from Config.Validate, or ErrDuplicateName when the name is already taken. When c is flagged Default the flag is cleared on every other configuration.
func (*Store) Default ¶
Default returns the configuration to launch when the caller does not name one: the flagged one, or the first in list order when no flag is set. Reports false only for an empty store.
func (*Store) List ¶
List returns every configuration in store order, deep-copied so the caller cannot mutate the store through the result.
func (*Store) Remove ¶
Remove deletes the configuration named name, reporting whether one was removed. Removing the default leaves no explicit default, so Default falls back to the first remaining configuration.
func (*Store) Save ¶
Save writes the store to path as indented JSON, creating the parent directory when needed (path is normally under a project-local dot directory that may not exist yet).
func (*Store) SetDefault ¶
SetDefault makes name the default configuration, clearing the flag everywhere else. Reports whether name exists.
func (*Store) Update ¶
Update replaces the configuration named name with c, keeping its position in the list. c may carry a different Name — a rename — as long as the new name is free. Returns ErrNotFound when name is unknown, ErrDuplicateName when the rename collides, or a validation error from Config.Validate; the store is untouched in every failure case.
Clearing c.Default drops the explicit default; Default then falls back to the first configuration.