state

package
v0.0.0-...-99f4f86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package state reads and writes .keel/state.json, the record of which modules keel init (and later keel add) selected for a generated project. Before this package existed, keel init left no trace of its own module selection anywhere in the generated output — keel add has nothing else to read to find out what's already present.

Index

Constants

View Source
const RelPath = ".keel/state.json"

RelPath is state.json's path relative to a project's root.

View Source
const SchemaVersion = 1

SchemaVersion is the current .keel/state.json schema. Bump it and handle migration explicitly if the shape ever needs to change — the same posture module.yaml's own apiVersion field takes.

Variables

View Source
var ErrNotFound = errors.New("state: no .keel/state.json found")

ErrNotFound is returned by Load when projectDir has no .keel/state.json — keel add turns this into its own "this directory wasn't generated by keel init" message; it is not itself a generic I/O error.

Functions

func Save

func Save(projectDir string, s *State) error

Save writes s to projectDir/.keel/state.json, creating .keel/ if necessary. s.Modules is sorted by name before writing — the same determinism requirement as go.mod's dependency sort and .env.example's var sort: repeated Save calls on an equivalent module set must be byte-identical.

Types

type Module

type Module struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Module records one resolved module's name and version. Deliberately nothing else — no content hash, no per-file record. Hashing would serve drift/upgrade detection, a different problem than keel add's actual need (knowing what's already selected, to compute a correct resolver.Resolve call); adding it now would be speculative scope for a problem nothing yet asks to solve.

type State

type State struct {
	SchemaVersion int      `json:"schemaVersion"`
	Language      string   `json:"language"`
	Modules       []Module `json:"modules"`
}

State is the decoded form of .keel/state.json.

func Load

func Load(projectDir string) (*State, error)

Load reads projectDir's .keel/state.json. Returns ErrNotFound if the file doesn't exist.

func (*State) Has

func (s *State) Has(name string) bool

Has reports whether s already lists a module named name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL