config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 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 provides configuration management for the AhaSend CLI.

This package handles:

  • Multi-profile authentication with API keys and account IDs
  • Configuration file loading and saving (YAML format)
  • Profile switching and management operations

All configuration is stored in ~/.ahasend/config.yaml following standard CLI conventions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDir added in v0.3.0

func EnsureDir() (string, error)

EnsureDir creates the CLI's directory, ~/.ahasend, readable by its owner only, tightens an existing one that other users can read, and returns its path.

func ProfileNames added in v0.3.0

func ProfileNames() []string

ProfileNames returns the names of the profiles in the configuration file, sorted, or none when there is no file or it cannot be read. It creates nothing and writes nothing, so shell completion can call it.

func Update added in v0.3.0

func Update(stderr io.Writer, change func(*Manager) error) error

Update loads the configuration, calls change with it and saves it when change returns nil, all under the exclusive lock of the configuration directory, so two commands that change the configuration at once never lose each other's changes. When another command holds the lock for more than lockWaitNotice, Update says on stderr that it waits for the lock file. change's error is returned as it is.

Types

type Config

type Config struct {
	DefaultProfile string               `yaml:"default_profile"`
	Profiles       map[string]Profile   `yaml:"profiles"`
	Extra          map[string]yaml.Node `yaml:",inline"`
}

Config represents the CLI configuration. Each level keeps the keys the CLI does not know in Extra, so saving the file never drops them; comments are not kept.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles configuration loading and saving

func LoadManager added in v0.3.0

func LoadManager() (*Manager, error)

LoadManager returns a Manager with the configuration file loaded, or the configuration error that stopped it. Commands that change the configuration use Update instead.

func NewManager

func NewManager() (*Manager, error)

NewManager creates a new configuration manager

func (*Manager) GetConfig

func (m *Manager) GetConfig() *Config

GetConfig returns the current configuration

func (*Manager) GetProfile added in v0.3.0

func (m *Manager) GetProfile(name string) (Profile, error)

GetProfile returns the profile that name refers to, as ProfileName finds it, or the error ProfileName returns.

func (*Manager) ListProfiles

func (m *Manager) ListProfiles() []string

ListProfiles returns all profile names

func (*Manager) Load

func (m *Manager) Load() error

Load loads the configuration file. A missing file leaves the defaults. Profile names are kept exactly as written; keys the CLI does not know are kept for Save. A default_profile that names a profile in another case, as v0.2.0, which matched names ignoring case, could save it, becomes the name of that profile, as ProfileName finds it, so every comparison with it is exact, and Save writes it so.

func (*Manager) NewProfileName added in v0.3.0

func (m *Manager) NewProfileName(name string) (string, error)

NewProfileName returns the name of the profile that name refers to, as ProfileName finds it, or "" when there is none, so a profile of that name can be added. Several profiles that match name ignoring case are ProfileName's configuration error.

func (*Manager) ProfileName added in v0.3.0

func (m *Manager) ProfileName(name string) (string, error)

ProfileName returns the name of the profile that name refers to: the profile called name or, when there is none, the one profile whose name matches name ignoring case. v0.2.0 matched profile names ignoring case, so a file it saved with "Prod" was used with --profile prod. Without such a profile, the error is the configuration error "profile '<name>' not found", which lists the profiles that match name ignoring case when there are several.

func (*Manager) ResolveProfile added in v0.3.0

func (m *Manager) ResolveProfile(name string) (string, Profile, error)

ResolveProfile returns the name and the profile a command authenticates with: the profile that name refers to, as ProfileName finds it, or the default profile when name is empty. Without any profile, the error is the authentication error that asks to log in; a profile that does not exist, a missing default and a profile whose api_url is not an API URL, whose api_key is empty or whose account_id is not a UUID are configuration errors.

func (*Manager) Save

func (m *Manager) Save() error

Save writes the configuration file. The file holds API keys, so it is readable by its owner only, and so is its directory. The new content goes to a temporary file in the same directory that then replaces the file, so a crash never leaves a partly written configuration. When the file is a symlink, the file it points to is replaced, so the symlink stays.

func (*Manager) SetDefaultProfile

func (m *Manager) SetDefaultProfile(name string) error

SetDefaultProfile sets the default profile. Save writes the change.

func (*Manager) SetProfile

func (m *Manager) SetProfile(name string, profile Profile) error

SetProfile adds or updates a profile. Save writes the change.

type Profile

type Profile struct {
	APIKey    string               `yaml:"api_key"`
	APIURL    string               `yaml:"api_url"`
	AccountID string               `yaml:"account_id"`
	Extra     map[string]yaml.Node `yaml:",inline"`
}

Profile represents an AhaSend account profile

type ProfileManager

type ProfileManager struct {
	// contains filtered or unexported fields
}

ProfileManager handles profile-specific operations

func (*ProfileManager) ListProfiles

func (pm *ProfileManager) ListProfiles() []string

ListProfiles returns a list of all profile names

func (*ProfileManager) SetDefaultProfile

func (pm *ProfileManager) SetDefaultProfile(name string) error

SetDefaultProfile sets the default profile

func (*ProfileManager) SetProfile

func (pm *ProfileManager) SetProfile(name string, profile Profile) error

SetProfile adds or updates a profile

Jump to

Keyboard shortcuts

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