contract

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package contract models notenv.toml, the committed contract declaring which env vars a project needs. It contains no values.

Index

Constants

View Source
const FileName = "notenv.toml"

Variables

View Source
var ErrNotFound = errors.New("no " + FileName + " found (run `notenv init` in your project root)")

ErrNotFound is returned by Find when no notenv.toml exists between the start directory and the filesystem root.

View Source
var NamespaceName = regexp.MustCompile(`^[A-Za-z0-9_][A-Za-z0-9._-]*$`)

NamespaceName constrains namespaces: they become remote object names. Must start with an alphanumeric or underscore, which excludes the path-significant names "." and ".." (and any leading "-"), while still allowing dots/dashes internally.

Functions

func Declare

func Declare(path, key string) error

Declare appends a secret declaration to the contract file's [secrets] section (creating the section if absent). Textual insert, not a TOML rewrite, so the user's comments and layout survive.

Types

type File

type File struct {
	Namespace string          `toml:"namespace"`
	Secrets   map[string]Spec `toml:"secrets"`
}

func Find

func Find(start string) (*File, string, error)

Find walks up from start to the filesystem root looking for notenv.toml (like git does for .git) and parses the first one found. Returns the parsed file and the directory containing it.

func Parse

func Parse(path string) (*File, error)

func (*File) BuildEnv

func (f *File) BuildEnv(base []string, secrets map[string]string) ([]string, error)

BuildEnv appends the contract's env vars (resolved from secrets) to base. Missing required secrets are an error; missing optional ones are skipped. os/exec deduplicates by key with last-wins, so appending overrides base.

func (*File) StorageKey

func (f *File) StorageKey(envKey string) string

StorageKey maps an env var name to the key it is stored under.

type Spec

type Spec struct {
	// Name overrides the storage key (defaults to the env var name).
	Name string `toml:"name"`
	// Required defaults to true: declaring a secret means you need it.
	Required *bool `toml:"required"`
}

Spec describes one declared secret.

func (Spec) IsRequired

func (s Spec) IsRequired() bool

Jump to

Keyboard shortcuts

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