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 ¶
- type Config
- type ConfigManager
- type ConfigStorage
- type Manager
- func (m *Manager) GetConfig() *Config
- func (m *Manager) GetCurrentProfile() (*Profile, error)
- func (m *Manager) GetPreference(key string) (string, error)
- func (m *Manager) ListProfiles() []string
- func (m *Manager) Load() error
- func (m *Manager) RemoveProfile(name string) error
- func (m *Manager) Save() error
- func (m *Manager) SetDefaultProfile(name string) error
- func (m *Manager) SetPreference(key, value string) error
- func (m *Manager) SetProfile(name string, profile Profile) error
- type ManagerV2
- func (m *ManagerV2) GetAllPreferences() map[string]string
- func (m *ManagerV2) GetConfig() *Config
- func (m *ManagerV2) GetCurrentProfile() (*Profile, error)
- func (m *ManagerV2) GetPreference(key string) (string, error)
- func (m *ManagerV2) GetProfile(name string) (*Profile, error)
- func (m *ManagerV2) ListProfiles() []string
- func (m *ManagerV2) Load() error
- func (m *ManagerV2) RemoveProfile(name string) error
- func (m *ManagerV2) Save() error
- func (m *ManagerV2) SetDefaultProfile(name string) error
- func (m *ManagerV2) SetPreference(key, value string) error
- func (m *ManagerV2) SetProfile(name string, profile Profile) error
- type PreferenceManager
- type Preferences
- type Profile
- type ProfileManager
- func (pm *ProfileManager) GetCurrentProfile() (*Profile, error)
- func (pm *ProfileManager) GetProfile(name string) (*Profile, error)
- func (pm *ProfileManager) ListProfiles() []string
- func (pm *ProfileManager) RemoveProfile(name string) error
- func (pm *ProfileManager) SetDefaultProfile(name string) error
- func (pm *ProfileManager) SetProfile(name string, profile Profile) error
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 ¶
NewManager creates a new configuration manager
func (*Manager) GetCurrentProfile ¶
GetCurrentProfile returns the current active profile
func (*Manager) GetPreference ¶
GetPreference gets a preference value
func (*Manager) ListProfiles ¶
ListProfiles returns all profile names
func (*Manager) RemoveProfile ¶
RemoveProfile removes a profile
func (*Manager) SetDefaultProfile ¶
SetDefaultProfile sets the default profile
func (*Manager) SetPreference ¶
SetPreference sets a preference value
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 ¶
NewManagerV2 creates a new refactored configuration manager
func (*ManagerV2) GetAllPreferences ¶
GetAllPreferences returns all preferences as a map
func (*ManagerV2) GetCurrentProfile ¶
GetCurrentProfile returns the current default profile
func (*ManagerV2) GetPreference ¶
GetPreference gets a preference value
func (*ManagerV2) GetProfile ¶
GetProfile returns a specific profile by name
func (*ManagerV2) ListProfiles ¶
ListProfiles returns all profile names
func (*ManagerV2) RemoveProfile ¶
RemoveProfile removes a profile
func (*ManagerV2) SetDefaultProfile ¶
SetDefaultProfile sets the default profile
func (*ManagerV2) SetPreference ¶
SetPreference sets a preference value with validation
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