Documentation ¶
Overview ¶
Package config provides types and functions to collect, validate and apply user-provided settings.
Index ¶
- Constants
- func CompareConfig(got Config, wanted Config, t *testing.T)
- func GetStructTag(c Config, fieldname string, tagName string) (string, bool)
- func MergeConfig(destination *Config, source Config) error
- func WriteDefaultHelpText(appName string)
- type AppMetadata
- type Config
- func (c Config) Description() string
- func (c *Config) GetAppDescription() string
- func (c *Config) GetAppName() string
- func (c *Config) GetAppURL() string
- func (c *Config) GetAppVersion() string
- func (c *Config) GetConfigFile() string
- func (c *Config) GetConsoleOutput() string
- func (c *Config) GetFileAge() int
- func (c *Config) GetFileExtensions() []string
- func (c *Config) GetFilePattern() string
- func (c *Config) GetFlagParser() *arg.Parser
- func (c *Config) GetIgnoreErrors() bool
- func (c *Config) GetKeepOldest() bool
- func (c *Config) GetLogFileHandle() *os.File
- func (c *Config) GetLogFilePath() string
- func (c *Config) GetLogFormat() string
- func (c *Config) GetLogLevel() string
- func (c *Config) GetLogger() *logrus.Logger
- func (c *Config) GetNumFilesToKeep() int
- func (c *Config) GetPaths() []string
- func (c *Config) GetRecursiveSearch() bool
- func (c *Config) GetRemove() bool
- func (c *Config) GetUseSyslog() bool
- func (c *Config) LoadConfigFile(fileHandle io.Reader) error
- func (c *Config) SetDefaultConfig()
- func (c *Config) SetLoggerConfig() error
- func (c *Config) String() string
- func (c Config) Validate() error
- func (c Config) Version() string
- type FileHandling
- type Logging
- type Search
Constants ¶
const ( FakeValue string = "fakeValue" FieldValueNotSet string = "NotSet" WindowsOSName string = "windows" WindowsAppSuffix string = ".exe" )
Workarounds for golantci-lint errors: string `STRING` has N occurrences, make it a constant (goconst)
const ( // DefaultAppName is the default name for this application DefaultAppName string = "elbow" // DefaultAppDescription is the description for this application shown in // HelpText output. DefaultAppDescription string = "prunes content matching specific patterns, either in a single directory or recursively through a directory tree." // DefaultAppURL is the website where users can learn more about the // application, submit problem reports, etc. DefaultAppURL string = "https://github.com/atc0005/elbow" )
Variables ¶
This section is empty.
Functions ¶
func CompareConfig ¶
CompareConfig receives two Config objects and compares exported field values to determine equality.
func GetStructTag ¶
GetStructTag returns the requested struct tag value, if set, and an error value indicating whether any problems were encountered.
func MergeConfig ¶
MergeConfig receives source and destination Config objects and merges select, non-nil field values from the source Config object to the destination config object, overwriting any field value already present.
The goal is to respect the current documented configuration precedence for multiple configuration sources (e.g., config file and command-line flags).
func WriteDefaultHelpText ¶
func WriteDefaultHelpText(appName string)
WriteDefaultHelpText is a helper function used to output Help text for situations where the Config object cannot be trusted to be in a usable state. TODO: Reconsider this; this feels fragile.
Types ¶
type AppMetadata ¶
type AppMetadata struct { AppName string `toml:"-" arg:"-"` AppDescription string `toml:"-" arg:"-"` AppVersion string `toml:"-" arg:"-"` AppURL string `toml:"-" arg:"-"` }
AppMetadata represents data about this application that may be used in Help output, error messages and potentially log messages (e.g., AppVersion)
type Config ¶
type Config struct { // Embed other structs in an effort to better group related settings. // Explicitly name embedded structs using the `toml` struct tag for // pelletier/toml v2 compatibility (which reflects stdlib's encoding/json // behavior). // // See also: // https://github.com/atc0005/elbow/issues/386 // https://github.com/pelletier/go-toml/issues/772 AppMetadata `toml:"-"` FileHandling `toml:"filehandling"` Logging `toml:"logging"` Search `toml:"search"` // Path to (optional) configuration file ConfigFile *string `` /* 172-byte string literal not displayed */ // contains filtered or unexported fields }
Config represents a collection of configuration settings for this application. Config is created as early as possible upon application startup.
func NewConfig ¶
NewConfig returns a pointer to a newly configured object representing a collection of user-provided and default settings.
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig returns a newly constructed config object composed of default configuration settings.
func (Config) Description ¶
Description provides an overview as part of the application Help output
func (*Config) GetAppDescription ¶
GetAppDescription returns the AppDescription field if it's non-nil, app default value otherwise
func (*Config) GetAppName ¶
GetAppName returns the AppName field if it's non-nil, app default value otherwise
func (*Config) GetAppURL ¶
GetAppURL returns the AppURL field if it's non-nil, app default value otherwise
func (*Config) GetAppVersion ¶
GetAppVersion returns the AppVersion field if it's non-nil, app default value otherwise
func (*Config) GetConfigFile ¶
GetConfigFile returns the ConfigFile field if it's non-nil, zero value otherwise.
func (*Config) GetConsoleOutput ¶
GetConsoleOutput returns the ConsoleOutput field if it's non-nil, zero value otherwise.
func (*Config) GetFileAge ¶
GetFileAge returns the FileAge field if it's non-nil, app default value otherwise
func (*Config) GetFileExtensions ¶
GetFileExtensions returns the FileExtensions field if it's non-nil, zero value otherwise. TODO: Double check this one; how should we safely handle returning an empty/zero value? As an example, the https://github.com/google/go-github package has a `Issue.GetAssignees()` method that returns nil if the `Issue.Assignees` field is nil. This seems to suggest that this is all we really can do here?
func (*Config) GetFilePattern ¶
GetFilePattern returns the FilePattern field if it's non-nil, app default value otherwise
func (*Config) GetFlagParser ¶
func (c *Config) GetFlagParser() *arg.Parser
GetFlagParser returns the flagParser field if it's non-nil, app default value otherwise
func (*Config) GetIgnoreErrors ¶
GetIgnoreErrors returns the IgnoreErrors field if it's non-nil, zero value otherwise.
func (*Config) GetKeepOldest ¶
GetKeepOldest returns the KeepOldest field if it's non-nil, zero value otherwise.
func (*Config) GetLogFileHandle ¶
GetLogFileHandle returns the logFileHandle field if it's non-nil, app default value otherwise
func (*Config) GetLogFilePath ¶
GetLogFilePath returns the LogFilePath field if it's non-nil, zero value otherwise.
func (*Config) GetLogFormat ¶
GetLogFormat returns the LogFormat field if it's non-nil, app default value otherwise
func (*Config) GetLogLevel ¶
GetLogLevel returns the LogLevel field if it's non-nil, app default value otherwise
func (*Config) GetLogger ¶
GetLogger returns the logger field if it's non-nil, app default value otherwise
func (*Config) GetNumFilesToKeep ¶
GetNumFilesToKeep returns the NumFilesToKeep field if it's non-nil, zero value otherwise.
func (*Config) GetPaths ¶
GetPaths returns the Paths field if it's non-nil, app default value otherwise
func (*Config) GetRecursiveSearch ¶
GetRecursiveSearch returns the RecursiveSearch field if it's non-nil, zero value otherwise.
func (*Config) GetRemove ¶
GetRemove returns the Remove field if it's non-nil, app default value otherwise
func (*Config) GetUseSyslog ¶
GetUseSyslog returns the UseSyslog field if it's non-nil, zero value otherwise.
func (*Config) LoadConfigFile ¶
LoadConfigFile reads from an io.Reader and unmarshals a configuration file in TOML format into the associated Config struct.
func (*Config) SetDefaultConfig ¶
func (c *Config) SetDefaultConfig()
SetDefaultConfig applies application default values to Config object fields TODO: Is this still needed? NewDefaultConfig() is handling this now?
func (*Config) SetLoggerConfig ¶
SetLoggerConfig applies chosen configuration settings that control logging output.
func (*Config) String ¶
String satisfies the Stringer interface. This is intended for non-JSON formatting if using the TextFormatter logrus formatter.
type FileHandling ¶
type FileHandling struct { FilePattern *string `` /* 137-byte string literal not displayed */ FileExtensions []string `` /* 229-byte string literal not displayed */ FileAge *int `` /* 127-byte string literal not displayed */ NumFilesToKeep *int `toml:"files_to_keep" arg:"--keep,env:ELBOW_KEEP" help:"Keep specified number of matching files per provided path."` KeepOldest *bool `toml:"keep_oldest" arg:"--keep-old,env:ELBOW_KEEP_OLD" help:"Keep oldest files instead of newer per provided path."` Remove *bool `toml:"remove" arg:"--remove,env:ELBOW_REMOVE" help:"Remove matched files per provided path."` IgnoreErrors *bool `toml:"ignore_errors" arg:"--ignore-errors,env:ELBOW_IGNORE_ERRORS" help:"Ignore errors encountered during file removal."` }
FileHandling represents options specific to how this application handles files.
type Logging ¶
type Logging struct { LogLevel *string `` /* 166-byte string literal not displayed */ LogFormat *string `toml:"log_format" arg:"--log-format,env:ELBOW_LOG_FORMAT" help:"Log formatter used by logging package."` LogFilePath *string `` /* 166-byte string literal not displayed */ ConsoleOutput *string `` /* 128-byte string literal not displayed */ UseSyslog *bool `` /* 143-byte string literal not displayed */ }
Logging represents options specific to how this application handles logging.
type Search ¶
type Search struct { Paths []string `toml:"paths" arg:"--paths,env:ELBOW_PATHS" help:"List of comma or space-separated paths to process."` RecursiveSearch *bool `` /* 128-byte string literal not displayed */ }
Search represents options specific to controlling how this application performs searches in the filesystem