config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config loads and validates archdoc.json.

Index

Constants

View Source
const (
	DefaultBranch       = "main"
	DefaultRoot         = "."
	DefaultStrict       = true
	DefaultRefStaleDays = 180
)

Defaults for keys absent from archdoc.json. Name has no default and is required.

View Source
const Filename = "archdoc.json"

Filename is the name of the configuration file, searched for by Find.

Variables

View Source
var ErrNotFound = errors.New("no archdoc.json found")

ErrNotFound reports that no archdoc.json exists in the starting directory or any of its ancestors.

Functions

func Validate

func Validate(c *Config) error

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

func ValidateRoot(root string) error

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"`

	// 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

func Find(dir string) (*Config, error)

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.

func Load

func Load(path string) (*Config, error)

Load reads and validates the archdoc.json at path.

func (*Config) Dir

func (c *Config) Dir() string

Dir is the directory holding archdoc.json. Root is relative to it.

func (*Config) RootDir

func (c *Config) RootDir() string

RootDir is the absolute directory holding the four document directories, and everything else archdoc generates. ValidateRoot, which Load applies, is what keeps it inside the repository.

Jump to

Keyboard shortcuts

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