Documentation
¶
Overview ¶
Package config is a helper package to facilitate getting and setting config values using Viper.
This package provides functions to read and write configuration settings for the eng CLI tool. It supports various configuration file formats and allows for easy management of local configuration settings.
Key features: - Load configuration from JSON, YAML, TOML, and other formats. - Set and get configuration values programmatically. - Support for environment variable overrides. - Easy integration with the Viper library.
These are local configs related to the eng CLI, not deployment configs.
Index ¶
- Variables
- func AddProject(project Project) error
- func AddRepoToProject(projectName string, repo ProjectRepo) error
- func BareRepoPath() string
- func Branch() string
- func DisableAllProxies() error
- func DotfilesRepo() string
- func Email() string
- func FindProxyIndexByTitle(proxies []ProxyConfig, title string) int
- func FormatProxyOption(proxy ProxyConfig) string
- func GetActiveProxy() (string, bool)
- func GetDotfilesRepo()
- func GetEmail()
- func GetProjectNames() []string
- func GitDevPath() string
- func IsVerbose() bool
- func MigrateConfig()
- func NormalizeProxyURLString(value string) string
- func PromptProxyValuesImpl(initialTitle, initialValue, initialNoProxy string) (title, value, noProxy string, err error)
- func RemoveProject(projectName string) error
- func RemoveRepoFromProject(projectName, repoURL string) error
- func RepoNameFromURL(repoURL string) (string, error)
- func RepoURL() string
- func RunInteractiveEditor() error
- func SaveProjects(projects []Project) error
- func SaveProxyConfigsImpl(proxies []ProxyConfig) error
- func SelectProxy(proxies []ProxyConfig) (int, error)
- func SetProxyEnvVars(proxyValue string)
- func TestProxyConnection(proxyURLStr, targetURLStr string) (time.Duration, error)
- func UnsetProxyEnvVars()
- func UpdateBareRepoPath()
- func UpdateBranch()
- func UpdateDotfilesRepo()
- func UpdateRepoURL()
- func UpdateWorktreePath()
- func ValidateProxyURLString(value string) error
- func Verbose() bool
- func VerifyDotfilesConfig() (string, string, string, string, error)
- func WorktreePath() string
- type ContainersConfig
- type DotfilesConfig
- type GitConfig
- type Project
- type ProjectRepo
- type PromptProxyValuesFunc
- type ProxyConfig
- func AddOrUpdateProxy() ([]ProxyConfig, int)
- func AddOrUpdateProxyWithValues(title, value, noProxy string) ([]ProxyConfig, int, error)
- func EnableProxy(index int, proxies []ProxyConfig) ([]ProxyConfig, error)
- func GetProxyConfigs() ([]ProxyConfig, int)
- func RemoveProxy(index int) ([]ProxyConfig, error)
- type SaveProxyConfigsFunc
Constants ¶
This section is empty.
Variables ¶
var PromptProxyValues = PromptProxyValuesImpl
PromptProxyValues is a variable that holds the function to prompt for proxy values. This can be overridden in tests.
var SaveProxyConfigs = SaveProxyConfigsImpl
SaveProxyConfigs is a variable that holds the function to save proxy configurations This can be overridden in tests.
Functions ¶
func AddProject ¶
AddProject adds a new project or updates an existing one. If a project with the same name exists, it updates it; otherwise, it appends.
func AddRepoToProject ¶
func AddRepoToProject(projectName string, repo ProjectRepo) error
AddRepoToProject adds a repository to an existing project. Returns an error if the project doesn't exist.
func BareRepoPath ¶
func BareRepoPath() string
BareRepoPath checks for the bare repository path in the configuration and returns it.
func Branch ¶
func Branch() string
Branch checks for the dotfiles branch in the configuration and returns it.
func DisableAllProxies ¶
func DisableAllProxies() error
DisableAllProxies disables all proxy configurations and unsets environment variables.
func DotfilesRepo ¶
func DotfilesRepo() string
DotfilesRepo is an alias for BareRepoPath for backward compatibility with external callers.
func Email ¶
func Email() string
Email checks for the user's email in the configuration and prompts the user to confirm it. If the email is not found or the user does not confirm it, the function will call updateEmail() to update the email. It logs the start and success of the email checking process and returns the confirmed email as a string.
func FindProxyIndexByTitle ¶
func FindProxyIndexByTitle(proxies []ProxyConfig, title string) int
FindProxyIndexByTitle returns the index of the proxy matching the title (case-insensitive), or -1.
func FormatProxyOption ¶
func FormatProxyOption(proxy ProxyConfig) string
FormatProxyOption renders a single proxy as a stylized radio option string. Example: "● Corp Proxy (http://proxy:8080)" with colored markers and dimmed value.
func GetActiveProxy ¶
GetActiveProxy returns the currently active proxy value and true if any proxy is enabled If no proxy is enabled, returns the first proxy value and false If no proxies exist, returns an empty string and false.
func GetDotfilesRepo ¶
func GetDotfilesRepo()
GetDotfilesRepo logs the current dotfiles repository path.
func GetEmail ¶
func GetEmail()
GetEmail retrieves the user's email from the configuration. If the email is not found in the configuration, it prompts the user to update it. Logs the process of checking and finding the email.
func GetProjectNames ¶
func GetProjectNames() []string
GetProjectNames returns a list of all configured project names.
func GitDevPath ¶
func GitDevPath() string
GitDevPath checks for the development folder path in the configuration and prompts the user to confirm it. If the path is not found or the user does not confirm it, the function will call updateGitDevPath() to update the path. It logs the start and success of the path checking process and returns the confirmed path as a string.
func IsVerbose ¶ added in v1.15.0
func IsVerbose() bool
IsVerbose returns whether verbose mode is enabled globally via config or environment.
func MigrateConfig ¶
func MigrateConfig()
MigrateConfig handles the migration of old configuration keys to new standardized ones. It checks for old keys, moves their values to new keys if the new ones are empty, and saves the configuration if any changes were made.
func NormalizeProxyURLString ¶
NormalizeProxyURLString adds a default http scheme when missing.
func PromptProxyValuesImpl ¶ added in v1.15.0
func PromptProxyValuesImpl( initialTitle, initialValue, initialNoProxy string, ) (title, value, noProxy string, err error)
PromptProxyValuesImpl uses huh.NewForm to collect proxy details interactively.
func RemoveProject ¶
RemoveProject removes a project from the configuration.
func RemoveRepoFromProject ¶
RemoveRepoFromProject removes a repository from a project.
func RepoNameFromURL ¶
RepoNameFromURL extracts the repository name from a git URL. Supports both SSH (git@host:path/git.git) and HTTPS (https://host/path/git.git) formats.
func RepoURL ¶
func RepoURL() string
RepoURL checks for the dotfiles repository URL in the configuration and returns it.
func RunInteractiveEditor ¶ added in v1.16.0
func RunInteractiveEditor() error
RunInteractiveEditor launches a TUI to edit the CLI's configuration.
func SaveProjects ¶
SaveProjects persists the list of projects to the config file.
func SaveProxyConfigsImpl ¶
func SaveProxyConfigsImpl(proxies []ProxyConfig) error
SaveProxyConfigsImpl is the actual implementation of saving proxy configurations to viper config.
func SelectProxy ¶
func SelectProxy(proxies []ProxyConfig) (int, error)
SelectProxy prompts the user to select a proxy from the list and returns the index.
func SetProxyEnvVars ¶
func SetProxyEnvVars(proxyValue string)
SetProxyEnvVars sets all proxy-related environment variables to the provided value and handles custom no_proxy settings.
func TestProxyConnection ¶ added in v1.29.0
TestProxyConnection tests HTTP connectivity using the specified proxy URL.
func UnsetProxyEnvVars ¶
func UnsetProxyEnvVars()
UnsetProxyEnvVars unsets all proxy-related environment variables.
func UpdateBareRepoPath ¶
func UpdateBareRepoPath()
UpdateBareRepoPath prompts the user to input their bare repository path.
func UpdateBranch ¶
func UpdateBranch()
UpdateBranch prompts the user to select their dotfiles branch.
func UpdateDotfilesRepo ¶
func UpdateDotfilesRepo()
UpdateDotfilesRepo is an alias for UpdateBareRepoPath.
func UpdateRepoURL ¶
func UpdateRepoURL()
UpdateRepoURL prompts the user to input their dotfiles repository URL.
func UpdateWorktreePath ¶
func UpdateWorktreePath()
UpdateWorktreePath prompts the user to input their worktree path.
func ValidateProxyURLString ¶
ValidateProxyURLString validates the proxy URL string for scheme and host:port.
func Verbose ¶
func Verbose() bool
Verbose checks for the verbose setting in the configuration and prompts the user to confirm it. If the verbose setting is not found or the user does not confirm it, the function will call updateVerbose() to update the setting. It logs the start and success of the verbose checking process and returns the confirmed verbose setting as a bool.
func VerifyDotfilesConfig ¶
VerifyDotfilesConfig checks for Repo URL, Branch, and Bare Repo Path. If all are present, it offers a single multi-select to update them. If any are missing, it falls back to sequential mandatory prompts.
func WorktreePath ¶
func WorktreePath() string
WorktreePath checks for the worktree path in the configuration and returns it.
Types ¶
type ContainersConfig ¶ added in v1.25.0
type ContainersConfig struct {
Path string `mapstructure:"path"`
}
ContainersConfig holds container-related configuration.
func GetContainersConfig ¶ added in v1.25.0
func GetContainersConfig() ContainersConfig
GetContainersConfig retrieves the containers configuration from Viper.
type DotfilesConfig ¶ added in v1.15.0
type DotfilesConfig struct {
RepoURL string `mapstructure:"repo_url"`
Branch string `mapstructure:"branch"`
BareRepoPath string `mapstructure:"bare_repo_path"`
WorktreePath string `mapstructure:"worktree_path"`
}
DotfilesConfig holds all dotfiles-related configuration.
func GetDotfilesConfig ¶ added in v1.15.0
func GetDotfilesConfig() DotfilesConfig
GetDotfilesConfig retrieves the dotfiles configuration from Viper.
type GitConfig ¶ added in v1.15.0
type GitConfig struct {
DevPath string `mapstructure:"dev_path"`
Editor string `mapstructure:"editor"`
}
GitConfig holds all git-related configuration.
func GetGitConfig ¶ added in v1.15.0
func GetGitConfig() GitConfig
GetGitConfig retrieves the git configuration from Viper.
type Project ¶
type Project struct {
Name string `mapstructure:"name"`
Repos []ProjectRepo `mapstructure:"repos"`
}
Project represents a collection of related repositories.
func GetProjectByName ¶
GetProjectByName retrieves a specific project by name. Returns nil if not found.
func GetProjects ¶
func GetProjects() []Project
GetProjects retrieves the list of configured projects from the config file.
type ProjectRepo ¶
type ProjectRepo struct {
URL string `mapstructure:"url"`
Path string `mapstructure:"path,omitempty"` // Optional, defaults to repo name from URL
}
ProjectRepo represents a single repository within a project.
func (*ProjectRepo) GetEffectivePath ¶
func (r *ProjectRepo) GetEffectivePath() (string, error)
GetEffectivePath returns the effective path for a git. If Path is set, it uses that; otherwise, it derives from the URL.
type PromptProxyValuesFunc ¶ added in v1.15.0
type PromptProxyValuesFunc func(initialTitle, initialValue, initialNoProxy string) (title, value, noProxy string, err error)
PromptProxyValuesFunc defines the function type for prompting for proxy values.
type ProxyConfig ¶
ProxyConfig represents a single proxy configuration.
func AddOrUpdateProxy ¶
func AddOrUpdateProxy() ([]ProxyConfig, int)
AddOrUpdateProxy adds a new proxy or updates an existing one.
func AddOrUpdateProxyWithValues ¶
func AddOrUpdateProxyWithValues(title, value, noProxy string) ([]ProxyConfig, int, error)
AddOrUpdateProxyWithValues adds or updates a proxy using provided values (non-interactive). Returns updated proxies, the affected index, or an error.
func EnableProxy ¶
func EnableProxy(index int, proxies []ProxyConfig) ([]ProxyConfig, error)
EnableProxy enables the proxy at the given index and disables all others.
func GetProxyConfigs ¶
func GetProxyConfigs() ([]ProxyConfig, int)
GetProxyConfigs checks for proxy settings in the configuration and returns the current proxies and the index of the active proxy (-1 if none are active).
func RemoveProxy ¶ added in v1.29.0
func RemoveProxy(index int) ([]ProxyConfig, error)
RemoveProxy removes the proxy configuration at the specified index.
type SaveProxyConfigsFunc ¶
type SaveProxyConfigsFunc func(proxies []ProxyConfig) error
SaveProxyConfigsFunc defines the function type for saving proxy configs.