config

package
v0.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config provides comprehensive configuration management for the AhaSend CLI.

This package handles all aspects of CLI configuration including:

  • Multi-profile authentication with API keys and account IDs
  • User preferences (output format, colors, timeouts, concurrency)
  • Configuration file loading and saving (YAML format)
  • Profile switching and management operations
  • Validation of configuration values and preferences
  • Backward compatibility with existing configuration files

The package provides both a legacy Manager for compatibility and a new ManagerV2 with improved architecture using focused components. All configuration is stored in ~/.ahasend/config.yaml following standard CLI conventions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DefaultProfile string             `mapstructure:"default_profile" yaml:"default_profile"`
	Profiles       map[string]Profile `mapstructure:"profiles" yaml:"profiles"`
	Preferences    Preferences        `mapstructure:"preferences" yaml:"preferences"`
}

Config represents the CLI configuration

type ConfigManager

type ConfigManager interface {
	// Configuration file operations
	Load() error
	Save() error
	GetConfig() *Config

	// Profile management
	GetCurrentProfile() (*Profile, error)
	SetProfile(name string, profile Profile) error
	RemoveProfile(name string) error
	ListProfiles() []string
	SetDefaultProfile(name string) error

	// Preference management
	SetPreference(key, value string) error
	GetPreference(key string) (string, error)
}

ConfigManager defines the interface for configuration management operations This interface allows for better testability and mocking

type ConfigStorage

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

ConfigStorage handles configuration file operations

func NewConfigStorage

func NewConfigStorage() (*ConfigStorage, error)

NewConfigStorage creates a new configuration storage handler

func (*ConfigStorage) GetConfigDir

func (cs *ConfigStorage) GetConfigDir() string

GetConfigDir returns the configuration directory path

func (*ConfigStorage) GetConfigPath

func (cs *ConfigStorage) GetConfigPath() string

GetConfigPath returns the configuration file path

func (*ConfigStorage) Load

func (cs *ConfigStorage) Load() (*Config, error)

Load loads configuration from file

func (*ConfigStorage) Save

func (cs *ConfigStorage) Save(config *Config) error

Save saves configuration to file

type Manager

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

Manager handles configuration loading and saving This is kept for backward compatibility - new code should use ManagerV2

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) GetCurrentProfile

func (m *Manager) GetCurrentProfile() (*Profile, error)

GetCurrentProfile returns the current active profile

func (*Manager) GetPreference

func (m *Manager) GetPreference(key string) (string, error)

GetPreference gets a preference value

func (*Manager) ListProfiles

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

ListProfiles returns all profile names

func (*Manager) Load

func (m *Manager) Load() error

Load loads configuration from file

func (*Manager) RemoveProfile

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

RemoveProfile removes a profile

func (*Manager) Save

func (m *Manager) Save() error

Save saves configuration to file

func (*Manager) SetDefaultProfile

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

SetDefaultProfile sets the default profile

func (*Manager) SetPreference

func (m *Manager) SetPreference(key, value string) error

SetPreference sets a preference value

func (*Manager) SetProfile

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

SetProfile adds or updates a profile

type ManagerV2

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

ManagerV2 coordinates configuration operations using focused components This is the new refactored manager that replaces the monolithic Manager

func NewManagerV2

func NewManagerV2() (*ManagerV2, error)

NewManagerV2 creates a new refactored configuration manager

func (*ManagerV2) GetAllPreferences

func (m *ManagerV2) GetAllPreferences() map[string]string

GetAllPreferences returns all preferences as a map

func (*ManagerV2) GetConfig

func (m *ManagerV2) GetConfig() *Config

GetConfig returns the current configuration

func (*ManagerV2) GetCurrentProfile

func (m *ManagerV2) GetCurrentProfile() (*Profile, error)

GetCurrentProfile returns the current default profile

func (*ManagerV2) GetPreference

func (m *ManagerV2) GetPreference(key string) (string, error)

GetPreference gets a preference value

func (*ManagerV2) GetProfile

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

GetProfile returns a specific profile by name

func (*ManagerV2) ListProfiles

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

ListProfiles returns all profile names

func (*ManagerV2) Load

func (m *ManagerV2) Load() error

Load reloads configuration from file

func (*ManagerV2) RemoveProfile

func (m *ManagerV2) RemoveProfile(name string) error

RemoveProfile removes a profile

func (*ManagerV2) Save

func (m *ManagerV2) Save() error

Save saves configuration to file

func (*ManagerV2) SetDefaultProfile

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

SetDefaultProfile sets the default profile

func (*ManagerV2) SetPreference

func (m *ManagerV2) SetPreference(key, value string) error

SetPreference sets a preference value with validation

func (*ManagerV2) SetProfile

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

SetProfile adds or updates a profile

type PreferenceManager

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

PreferenceManager handles preference operations with validation

func NewPreferenceManager

func NewPreferenceManager(config *Config) *PreferenceManager

NewPreferenceManager creates a new preference manager

func (*PreferenceManager) GetAllPreferences

func (pm *PreferenceManager) GetAllPreferences() map[string]string

GetAllPreferences returns all preferences as a map

func (*PreferenceManager) GetPreference

func (pm *PreferenceManager) GetPreference(key string) (string, error)

GetPreference gets a preference value

func (*PreferenceManager) SetPreference

func (pm *PreferenceManager) SetPreference(key, value string) error

SetPreference sets a preference value with validation

type Preferences

type Preferences struct {
	OutputFormat     string `mapstructure:"output_format" yaml:"output_format"`
	ColorOutput      bool   `mapstructure:"color_output" yaml:"color_output"`
	WebhookTimeout   string `mapstructure:"webhook_timeout" yaml:"webhook_timeout"`
	LogLevel         string `mapstructure:"log_level" yaml:"log_level"`
	DefaultDomain    string `mapstructure:"default_domain" yaml:"default_domain"`
	BatchConcurrency int    `mapstructure:"batch_concurrency" yaml:"batch_concurrency"`
}

Preferences represents user preferences for the CLI

func DefaultPreferences

func DefaultPreferences() Preferences

DefaultPreferences returns default preferences

type Profile

type Profile struct {
	APIKey         string    `mapstructure:"api_key" yaml:"api_key"`
	APIURL         string    `mapstructure:"api_url" yaml:"api_url"`
	AccountID      string    `mapstructure:"account_id" yaml:"account_id"`
	Name           string    `mapstructure:"name" yaml:"name"`
	AccountName    string    `mapstructure:"account_name" yaml:"account_name,omitempty"`
	AccountUpdated time.Time `mapstructure:"account_updated" yaml:"account_updated,omitempty"`
}

Profile represents an AhaSend account profile

type ProfileManager

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

ProfileManager handles profile-specific operations

func NewProfileManager

func NewProfileManager(config *Config) *ProfileManager

NewProfileManager creates a new profile manager

func (*ProfileManager) GetCurrentProfile

func (pm *ProfileManager) GetCurrentProfile() (*Profile, error)

GetCurrentProfile returns the current default profile

func (*ProfileManager) GetProfile

func (pm *ProfileManager) GetProfile(name string) (*Profile, error)

GetProfile returns a specific profile by name

func (*ProfileManager) ListProfiles

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

ListProfiles returns a list of all profile names

func (*ProfileManager) RemoveProfile

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

RemoveProfile removes a profile (cannot remove default profile)

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