Documentation
¶
Overview ¶
Package config loads and validates archdoc.json.
Index ¶
Constants ¶
const ( DefaultBranch = "main" DefaultRoot = "." DefaultStrict = true DefaultRefStaleDays = 180 )
Defaults for keys absent from archdoc.json. Name has no default and is required.
const Filename = "archdoc.json"
Filename is the name of the configuration file, searched for by Find.
Variables ¶
var ErrNotFound = errors.New("no archdoc.json found")
ErrNotFound reports that no archdoc.json exists in the starting directory or any of its ancestors.
var Keys = []Key{ {Name: "name", Type: "string", Required: true}, {Name: "branch", Type: "string", Default: DefaultBranch}, {Name: "root", Type: "string", Default: DefaultRoot}, {Name: "strict", Type: "boolean", Default: DefaultStrict}, {Name: "ref_stale_days", Type: "integer", Default: DefaultRefStaleDays}, {Name: "acknowledged", Type: "object", Default: map[string][]string{}}, }
Keys is every key of archdoc.json, in the order init writes them.
Functions ¶
func Validate ¶
Validate is every check Load applies to a configuration, exported so that `archdoc init` can apply them to the settings it is about to write rather than discovering them when it reads the file back.
It used to discover them there: init wrote the whole scaffold and then failed loading its own archdoc.json, leaving a dead configuration behind that made init refuse to run again and every other command fail. The checks it did mirror ran before the interactive prompts, so a root typed at the prompt was checked by nothing at all.
func ValidateRoot ¶
ValidateRoot reports whether root names a directory inside the repository.
root exists so that a specification can live in a subdirectory of the project it documents, and nothing else: an unchecked "../victim" made archdoc write INDEX.md, and create a glossary, in a directory nobody named. The check is lexical, which is the same shape as the paths it guards.
Types ¶
type Config ¶
type Config struct {
Name string `json:"name"`
Branch string `json:"branch"`
Root string `json:"root"`
Strict bool `json:"strict"`
RefStaleDays int `json:"ref_stale_days"`
// Acknowledged names frozen documents, by path within root, and the rules
// whose warnings on each are accepted. Which paths and codes these are is
// not checked here, since this package knows neither: L22 reports both.
//
// Left out where empty, so init does not write it: a release before the
// one reading it refuses the key, and a repository acknowledging nothing
// must not fail under such a pin.
Acknowledged map[string][]string `json:"acknowledged,omitempty"`
// Path is the absolute location of the archdoc.json this was loaded from.
// It is not part of the file, and naming it here keeps a document that
// mentions "path" an unknown-field error rather than a way to set it.
Path string `json:"-"`
}
Config is the contents of archdoc.json.
func Find ¶
Find walks up from dir looking for archdoc.json and loads the first one it finds. It returns ErrNotFound if it reaches the filesystem root first.
type Key ¶ added in v0.6.0
type Key struct {
Name string
// Type is the key's JSON type.
Type string
Required bool
// Default is what Load applies where the key is absent, nil for a
// required key.
Default any
}
Key is one key of archdoc.json, as the reference publishes it.
type Settings ¶ added in v0.6.0
Settings is what L11 and the merge rules read from an archdoc.json as it stands on a branch: its root and strict. Its branch is not read: the base is found through the working tree's.
func SettingsIn ¶ added in v0.6.0
SettingsIn reads those settings from an archdoc.json's contents, as Load decides them for a file Load accepts, without validating anything else. It is for a configuration as it stands on a branch, which is never loaded from disk, and is lenient on purpose: a branch's archdoc.json written before a check Load now makes must not make the comparison fail.