config

package
v0.0.1-testing Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config manages the non-secret CLI configuration (~/.config/reearth/config.yaml) and project files (.reearth.yaml). Secrets never live here; see package credstore.

Index

Constants

View Source
const (
	KindOAuth = "oauth"
	KindToken = "token"
)

Account kinds.

Variables

View Source
var ErrNewerVersion = errors.New("written by a newer version of the CLI")

ErrNewerVersion is wrapped by the error LoadFile returns for a file written by a newer version of the CLI.

View Source
var Settings = []Setting{
	{Key: "output", Description: "Default output format on a TTY", Default: "table", Allowed: []string{"table", "plain", "json", "yaml", "ndjson"}},
	{Key: "prompt", Description: "Allow interactive prompts", Default: "enabled", Allowed: []string{"enabled", "disabled"}},
	{Key: "update_check", Description: "Check for new reearth versions (reearth binary only)", Default: "enabled", Allowed: []string{"enabled", "disabled"}},
	{Key: "browser", Description: "Command used to open URLs (empty: system default)"},
}

Settings lists every supported setting key.

Functions

func CacheDir

func CacheDir() string

CacheDir returns the cache directory (tokens are never stored here).

func DataDir

func DataDir() string

DataDir returns the data directory (extensions live here).

func Dir

func Dir() string

Dir returns the configuration directory. REEARTH_CONFIG_DIR > XDG_CONFIG_HOME/reearth > %AppData%/reearth (Windows) > ~/.config/reearth

func Path

func Path() string

Path returns the path of the config file.

func SettingEnv

func SettingEnv(key string) string

SettingEnv returns the environment variable that overrides a setting.

Types

type Account

type Account struct {
	Env     string `yaml:"env" json:"env"`
	Kind    string `yaml:"kind" json:"kind"`
	Product string `yaml:"product,omitempty" json:"product,omitempty"`
	User    *User  `yaml:"user,omitempty" json:"user,omitempty"`
	// Workspace is the default workspace ID for this account.
	Workspace string `yaml:"workspace,omitempty" json:"workspace,omitempty"`
	// InsecureStorage stores credentials in a plain file instead of the OS keyring.
	InsecureStorage bool `yaml:"insecure_storage,omitempty" json:"insecure_storage,omitempty"`

	Extra map[string]any `yaml:",inline" json:"-"`
}

type Config

type Config struct {
	Version  int                   `yaml:"version"`
	Active   string                `yaml:"active,omitempty"`
	Accounts map[string]*Account   `yaml:"accounts,omitempty"`
	Envs     map[string]*EnvConfig `yaml:"envs,omitempty"`
	// Hostname is the hostname for the OAuth redirect listener (default: "127.0.0.1").
	Hostname string `yaml:"hostname,omitempty"`
	// Port fixes the OAuth loopback port used during login (0 = try 8085-8087).
	// Register http://<hostname>:<port>/callback in your Auth0 allowed callback URLs.
	Port int `yaml:"port,omitempty"`
	// Settings keeps values of keys this version does not know as written.
	Settings map[string]any `yaml:"settings,omitempty"`
	// Extra keeps top-level fields this version does not know, so that saving
	// does not erase what a newer version wrote. The nested structs below
	// keep theirs the same way.
	Extra map[string]any `yaml:",inline" json:"-"`
	// contains filtered or unexported fields
}

func Load

func Load() (*Config, error)

Load reads the config file. A missing file yields an empty config.

func LoadFile

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

func (*Config) AccountNames

func (c *Config) AccountNames() []string

AccountNames returns account names sorted alphabetically.

func (*Config) Get

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

Get resolves a setting: environment > config file > default.

func (*Config) Path

func (c *Config) Path() string

func (*Config) RemoveAccount

func (c *Config) RemoveAccount(name string)

RemoveAccount deletes an account and fixes up the active account.

func (*Config) Save

func (c *Config) Save() error

Save writes the config atomically with 0600 permissions.

func (*Config) Set

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

func (*Config) Unset

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

type EnvAuth

type EnvAuth struct {
	Domain   string `yaml:"domain"`
	ClientID string `yaml:"client_id"`
	Audience string `yaml:"audience,omitempty"`

	Extra map[string]any `yaml:",inline" json:"-"`
}

type EnvConfig

type EnvConfig struct {
	Auth     EnvAuth               `yaml:"auth"`
	Products map[string]EnvProduct `yaml:"products,omitempty"`

	Extra map[string]any `yaml:",inline" json:"-"`
}

EnvConfig is a user-defined environment (on-premise, self-hosted Auth0, ...).

type EnvProduct

type EnvProduct struct {
	BaseURL string `yaml:"base_url"`

	Extra map[string]any `yaml:",inline" json:"-"`
}

type Origin

type Origin string

Origin tells where a resolved value came from.

const (
	OriginDefault Origin = "default"
	OriginConfig  Origin = "config"
	OriginEnv     Origin = "env"
	OriginProject Origin = "project"
	OriginFlag    Origin = "flag"
)

type Project

type Project struct {
	Account   string                    `yaml:"account,omitempty"`
	Workspace string                    `yaml:"workspace,omitempty"`
	Products  map[string]map[string]any `yaml:",inline"`
	// contains filtered or unexported fields
}

Project is a per-directory config file (.reearth.yaml), meant to be committed.

account: work
workspace: 01hq...
cms:
  project: my-project

func FindProject

func FindProject(dir string) (*Project, error)

FindProject searches dir and its parents for a project file. It returns nil if none is found.

func (*Project) Path

func (p *Project) Path() string

func (*Project) Value

func (p *Project) Value(product, key string) (string, bool)

Value returns a product-scoped value such as cms.project.

type Setting

type Setting struct {
	Key         string
	Description string
	Default     string
	Allowed     []string // empty means free-form
}

Setting is a user-tunable key for `reearth config get/set`.

func LookupSetting

func LookupSetting(key string) (Setting, bool)

type User

type User struct {
	Sub   string `yaml:"sub" json:"sub"`
	Email string `yaml:"email,omitempty" json:"email,omitempty"`
	Name  string `yaml:"name,omitempty" json:"name,omitempty"`

	Extra map[string]any `yaml:",inline" json:"-"`
}

Jump to

Keyboard shortcuts

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