config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectFileName = "nimbu.yml"
	ProjectDirEnv   = "NIMBU_PROJECT_DIR"
)
View Source
const AppName = "nimbu"
View Source
const DefaultAPIHost = "api.nimbu.io"

DefaultAPIHost is the default API host, extracted from the default API URL.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the directory for configuration files. Uses ~/.config on macOS and Linux by default (or XDG_CONFIG_HOME on Linux), and %APPDATA% on Windows.

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the full path to the config file.

func DataDir

func DataDir() (string, error)

DataDir returns the directory for data files (like keyring fallback).

func DescribeProjectLookup added in v0.3.2

func DescribeProjectLookup(err error) string

DescribeProjectLookup renders the project file for user-facing error messages, e.g. `nimbu.yml (searched up to /home/me/site)`. Pass the error returned by a lookup; a nil or unrelated error falls back to a fresh search boundary computed from the current working directory.

func EnsureConfigDir

func EnsureConfigDir() (string, error)

EnsureConfigDir creates the config directory if it doesn't exist.

func EnsureDataDir

func EnsureDataDir() (string, error)

EnsureDataDir creates the data directory if it doesn't exist.

func FindProjectFile

func FindProjectFile() (string, error)

FindProjectFile locates nimbu.yml. Precedence:

  1. Walk up from NIMBU_PROJECT_DIR, if set (error if nothing is found).
  2. Walk up from the current working directory.
  3. If still missing, try the git top-level directory as an extra candidate.

Each walk stops at the filesystem root, or at the first directory holding a `.git` entry — that directory is still checked, nothing above it is.

func ParseRouteRule

func ParseRouteRule(raw string) (method string, pattern string)

ParseRouteRule parses either "<glob>" or "<METHOD> <glob>" route rules.

func ProjectRoot

func ProjectRoot() (string, error)

ProjectRoot returns the directory containing the nearest nimbu.yml.

func ProjectSearchLimit added in v0.3.2

func ProjectSearchLimit() string

ProjectSearchLimit returns the directory where an upward nimbu.yml search would stop: the enclosing git root when there is one, else the filesystem root. It returns "" when the start directory cannot be determined.

func UpdateEnvironment added in v0.3.3

func UpdateEnvironment(path, name string, value *EnvironmentConfig) error

UpdateEnvironment edits only the selected mapping, retaining unrelated YAML keys and comments. A nil value removes the environment.

func UpsertProjectApp

func UpsertProjectApp(path string, app AppProjectConfig) error

UpsertProjectApp inserts or replaces one app entry in nimbu.yml.

func ValidKeys

func ValidKeys() []string

ValidKeys returns all valid config keys.

func WarnUnknownAppsKeys

func WarnUnknownAppsKeys(path string) ([]string, error)

WarnUnknownAppsKeys returns warning strings for unknown keys in the `apps` block.

func WarnUnknownDevKeys

func WarnUnknownDevKeys(path string) ([]string, error)

WarnUnknownDevKeys returns warning strings for unknown keys in the `dev` block. Unknown keys are non-fatal and should be surfaced to users at startup.

func WarnUnknownEnvironmentKeys added in v0.3.3

func WarnUnknownEnvironmentKeys(path string) ([]string, error)

WarnUnknownEnvironmentKeys returns warnings for unknown environment settings.

func WarnUnknownSyncKeys

func WarnUnknownSyncKeys(path string) ([]string, error)

WarnUnknownSyncKeys returns warning strings for unknown keys in the `sync` block.

func Write

func Write(cfg Config) error

Write saves config to disk.

func WriteProjectConfig

func WriteProjectConfig(cfg ProjectConfig) error

WriteProjectConfig writes project config to nimbu.yml in the current directory.

func WriteProjectConfigTo

func WriteProjectConfigTo(path string, cfg ProjectConfig) error

WriteProjectConfigTo writes project config to a specific path.

Types

type AppProjectConfig

type AppProjectConfig struct {
	ID   string `json:"id,omitempty" yaml:"id,omitempty"`
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	Dir  string `json:"dir,omitempty" yaml:"dir,omitempty"`
	Glob string `json:"glob,omitempty" yaml:"glob,omitempty"`
	Host string `json:"host,omitempty" yaml:"host,omitempty"`
	Site string `json:"site,omitempty" yaml:"site,omitempty"`
}

AppProjectConfig configures one local cloud-code app mapping.

type Config

type Config struct {
	DefaultSite    string `json:"default_site,omitempty"`
	APIURL         string `json:"api_url,omitempty"`
	Timeout        string `json:"timeout,omitempty"`
	KeyringBackend string `json:"keyring_backend,omitempty"`
	BannerTheme    string `json:"banner_theme,omitempty"`
}

Config holds application configuration.

func Defaults

func Defaults() Config

Defaults returns config with default values.

func Read

func Read() (Config, error)

Read loads config from disk, merging with defaults.

func (*Config) Get

func (c *Config) Get(key string) (string, error)

Get retrieves a single config value by key.

func (*Config) Set

func (c *Config) Set(key, value string) error

Set updates a single config value by key.

func (*Config) TimeoutDuration

func (c *Config) TimeoutDuration() time.Duration

TimeoutDuration returns the timeout as a duration.

func (*Config) Unset

func (c *Config) Unset(key string) error

Unset removes a config value by key.

type DevConfig

type DevConfig struct {
	Proxy  DevProxyConfig  `json:"proxy,omitempty" yaml:"proxy,omitempty"`
	Routes DevRoutesConfig `json:"routes,omitempty" yaml:"routes,omitempty"`
	Server DevServerConfig `json:"server,omitempty" yaml:"server,omitempty"`
}

DevConfig holds local development server configuration.

type DevProxyConfig

type DevProxyConfig struct {
	Host              string `json:"host,omitempty" yaml:"host,omitempty"`
	MaxBodyMB         int    `json:"max_body_mb,omitempty" yaml:"max_body_mb,omitempty"`
	Port              int    `json:"port,omitempty" yaml:"port,omitempty"`
	TemplateRoot      string `json:"template_root,omitempty" yaml:"template_root,omitempty"`
	Watch             *bool  `json:"watch,omitempty" yaml:"watch,omitempty"`
	WatchScanInterval string `json:"watch_scan_interval,omitempty" yaml:"watch_scan_interval,omitempty"`
}

DevProxyConfig configures the local Nimbu proxy runtime.

type DevRoutesConfig

type DevRoutesConfig struct {
	Exclude []string `json:"exclude,omitempty" yaml:"exclude,omitempty"`
	Include []string `json:"include,omitempty" yaml:"include,omitempty"`
}

DevRoutesConfig configures include/exclude path rules for proxy routing.

Each rule accepts either: - "<glob>", e.g. "/**", "/account/*" - "<METHOD> <glob>", e.g. "POST /.well-known/*"

type DevServerConfig

type DevServerConfig struct {
	Args     []string          `json:"args,omitempty" yaml:"args,omitempty"`
	CWD      string            `json:"cwd,omitempty" yaml:"cwd,omitempty"`
	Command  string            `json:"command,omitempty" yaml:"command,omitempty"`
	Env      map[string]string `json:"env,omitempty" yaml:"env,omitempty"`
	ReadyURL string            `json:"ready_url,omitempty" yaml:"ready_url,omitempty"`
}

DevServerConfig configures the child development server process.

type EnvironmentConfig added in v0.3.3

type EnvironmentConfig struct {
	Host      string `json:"host" yaml:"host"`
	Site      string `json:"site" yaml:"site"`
	Protected bool   `json:"protected,omitempty" yaml:"protected,omitempty"`
}

EnvironmentConfig selects a site and API host together.

func (EnvironmentConfig) Validate added in v0.3.3

func (e EnvironmentConfig) Validate() error

type ProjectConfig

type ProjectConfig struct {
	Environments map[string]EnvironmentConfig `json:"environments,omitempty" yaml:"environments,omitempty"`
	Apps         []AppProjectConfig           `json:"apps,omitempty" yaml:"apps,omitempty"`
	Site         string                       `json:"site,omitempty" yaml:"site,omitempty"`
	Theme        string                       `json:"theme,omitempty" yaml:"theme,omitempty"`
	Dev          *DevConfig                   `json:"dev,omitempty" yaml:"dev,omitempty"`
	Sync         *SyncConfig                  `json:"sync,omitempty" yaml:"sync,omitempty"`
}

ProjectConfig holds project-specific configuration.

func ReadProjectConfig

func ReadProjectConfig() (ProjectConfig, error)

ReadProjectConfig reads the project config from nimbu.yml.

func ReadProjectConfigFrom

func ReadProjectConfigFrom(path string) (ProjectConfig, error)

ReadProjectConfigFrom reads project config from a specific path.

type ProjectLookupError added in v0.3.2

type ProjectLookupError struct {
	// StartDir is the directory the search started from.
	StartDir string
	// StoppedAt is the last directory that was inspected.
	StoppedAt string
	// EnvDriven reports whether the search started from NIMBU_PROJECT_DIR.
	EnvDriven bool
}

ProjectLookupError reports a failed nimbu.yml lookup together with the directory where the upward search stopped. It unwraps to ErrNotFound so existing errors.Is checks keep working.

func (*ProjectLookupError) Error added in v0.3.2

func (e *ProjectLookupError) Error() string

func (*ProjectLookupError) Unwrap added in v0.3.2

func (e *ProjectLookupError) Unwrap() error

type SyncBuildConfig

type SyncBuildConfig struct {
	Args    []string          `json:"args,omitempty" yaml:"args,omitempty"`
	CWD     string            `json:"cwd,omitempty" yaml:"cwd,omitempty"`
	Command string            `json:"command,omitempty" yaml:"command,omitempty"`
	Env     map[string]string `json:"env,omitempty" yaml:"env,omitempty"`
}

SyncBuildConfig configures the optional build step for theme push/sync.

type SyncConfig

type SyncConfig struct {
	Build     SyncBuildConfig `json:"build,omitempty" yaml:"build,omitempty"`
	Generated []string        `json:"generated,omitempty" yaml:"generated,omitempty"`
	Ignore    []string        `json:"ignore,omitempty" yaml:"ignore,omitempty"`
	Roots     SyncRootsConfig `json:"roots,omitempty" yaml:"roots,omitempty"`
}

SyncConfig configures theme push/sync behavior.

type SyncRootsConfig

type SyncRootsConfig struct {
	Assets    []string `json:"assets,omitempty" yaml:"assets,omitempty"`
	Layouts   []string `json:"layouts,omitempty" yaml:"layouts,omitempty"`
	Snippets  []string `json:"snippets,omitempty" yaml:"snippets,omitempty"`
	Templates []string `json:"templates,omitempty" yaml:"templates,omitempty"`
}

SyncRootsConfig groups local directories by remote theme resource kind.

Jump to

Keyboard shortcuts

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