config

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config handles configuration loading, saving, and access for the nuc CLI. Configuration is stored as YAML in an XDG-compliant location.

Index

Constants

View Source
const (

	// DefaultBaseURL is empty — Nucleus instances are per-org (e.g. nucleus-eu6.nucleussec.com).
	// Users must set base_url via config, --base-url flag, or NUC_BASE_URL env var.
	DefaultBaseURL = ""

	// DefaultOutputFormat is the default output format.
	DefaultOutputFormat = "table"
)

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir returns the configuration directory path. Uses os.UserConfigDir() which respects XDG_CONFIG_HOME on Linux, ~/Library/Application Support on macOS, and %AppData% on Windows.

func Keys

func Keys() []string

Keys returns all valid configuration key names.

func Path

func Path() (string, error)

Path returns the full path to the configuration file.

func Save

func Save(cfg *Config) error

Save writes the configuration to disk, creating the directory if needed. Directory permissions: 0700. File permissions: 0600.

func SaveTo

func SaveTo(cfg *Config, path string) error

SaveTo writes the configuration to a specific path.

Types

type Config

type Config struct {
	APIKey         string `yaml:"api_key,omitempty"`
	BaseURL        string `yaml:"base_url,omitempty"`
	DefaultProject string `yaml:"default_project,omitempty"`
	OutputFormat   string `yaml:"output_format,omitempty"`
}

Config represents the persisted CLI configuration.

func Load

func Load() (*Config, error)

Load reads the configuration from disk. Returns a zero-value Config (not an error) if the file does not exist. Returns an error if the file exists but contains invalid YAML.

func LoadFrom

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

LoadFrom reads the configuration from a specific path. Returns a zero-value Config (not an error) if the file does not exist.

func (*Config) BaseURLOrDefault

func (c *Config) BaseURLOrDefault() string

BaseURLOrDefault returns the configured base URL or the default if not set.

func (*Config) Get

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

Get returns the value for a configuration key. Returns an empty string for unknown keys.

func (*Config) OutputFormatOrDefault

func (c *Config) OutputFormatOrDefault() string

OutputFormatOrDefault returns the configured output format or the default if not set.

func (*Config) Set

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

Set sets a configuration value by key. Returns an error if the key is not in the valid allowlist.

Jump to

Keyboard shortcuts

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