config

package
v0.8.12 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config provides types and functions to collect, validate and apply user-provided settings.

Index

Constants

View Source
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)

View Source
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

func CompareConfig(got Config, wanted Config, t *testing.T)

CompareConfig receives two Config objects and compares exported field values to determine equality.

func GetStructTag

func GetStructTag(c Config, fieldname string, tagName string) (string, bool)

GetStructTag returns the requested struct tag value, if set, and an error value indicating whether any problems were encountered.

func MergeConfig

func MergeConfig(destination *Config, source Config) error

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

func NewConfig() (*Config, error)

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

func (c Config) Description() string

Description provides an overview as part of the application Help output

func (*Config) GetAppDescription

func (c *Config) GetAppDescription() string

GetAppDescription returns the AppDescription field if it's non-nil, app default value otherwise

func (*Config) GetAppName

func (c *Config) GetAppName() string

GetAppName returns the AppName field if it's non-nil, app default value otherwise

func (*Config) GetAppURL

func (c *Config) GetAppURL() string

GetAppURL returns the AppURL field if it's non-nil, app default value otherwise

func (*Config) GetAppVersion

func (c *Config) GetAppVersion() string

GetAppVersion returns the AppVersion field if it's non-nil, app default value otherwise

func (*Config) GetConfigFile

func (c *Config) GetConfigFile() string

GetConfigFile returns the ConfigFile field if it's non-nil, zero value otherwise.

func (*Config) GetConsoleOutput

func (c *Config) GetConsoleOutput() string

GetConsoleOutput returns the ConsoleOutput field if it's non-nil, zero value otherwise.

func (*Config) GetFileAge

func (c *Config) GetFileAge() int

GetFileAge returns the FileAge field if it's non-nil, app default value otherwise

func (*Config) GetFileExtensions

func (c *Config) GetFileExtensions() []string

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

func (c *Config) GetFilePattern() string

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

func (c *Config) GetIgnoreErrors() bool

GetIgnoreErrors returns the IgnoreErrors field if it's non-nil, zero value otherwise.

func (*Config) GetKeepOldest

func (c *Config) GetKeepOldest() bool

GetKeepOldest returns the KeepOldest field if it's non-nil, zero value otherwise.

func (*Config) GetLogFileHandle

func (c *Config) GetLogFileHandle() *os.File

GetLogFileHandle returns the logFileHandle field if it's non-nil, app default value otherwise

func (*Config) GetLogFilePath

func (c *Config) GetLogFilePath() string

GetLogFilePath returns the LogFilePath field if it's non-nil, zero value otherwise.

func (*Config) GetLogFormat

func (c *Config) GetLogFormat() string

GetLogFormat returns the LogFormat field if it's non-nil, app default value otherwise

func (*Config) GetLogLevel

func (c *Config) GetLogLevel() string

GetLogLevel returns the LogLevel field if it's non-nil, app default value otherwise

func (*Config) GetLogger

func (c *Config) GetLogger() *logrus.Logger

GetLogger returns the logger field if it's non-nil, app default value otherwise

func (*Config) GetNumFilesToKeep

func (c *Config) GetNumFilesToKeep() int

GetNumFilesToKeep returns the NumFilesToKeep field if it's non-nil, zero value otherwise.

func (*Config) GetPaths

func (c *Config) GetPaths() []string

GetPaths returns the Paths field if it's non-nil, app default value otherwise

func (*Config) GetRecursiveSearch

func (c *Config) GetRecursiveSearch() bool

GetRecursiveSearch returns the RecursiveSearch field if it's non-nil, zero value otherwise.

func (*Config) GetRemove

func (c *Config) GetRemove() bool

GetRemove returns the Remove field if it's non-nil, app default value otherwise

func (*Config) GetUseSyslog

func (c *Config) GetUseSyslog() bool

GetUseSyslog returns the UseSyslog field if it's non-nil, zero value otherwise.

func (*Config) LoadConfigFile

func (c *Config) LoadConfigFile(fileHandle io.Reader) error

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

func (c *Config) SetLoggerConfig() error

SetLoggerConfig applies chosen configuration settings that control logging output.

func (*Config) String

func (c *Config) String() string

String satisfies the Stringer interface. This is intended for non-JSON formatting if using the TextFormatter logrus formatter.

func (Config) Validate

func (c Config) Validate() error

Validate verifies all struct fields have been provided acceptable values

func (Config) Version

func (c Config) Version() string

Version provides a version string that appears at the top of the application Help output

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

Jump to

Keyboard shortcuts

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