config

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package config handles user inputs/UI elements.

Package config handles user inputs/UI elements.

Package config handles user inputs/UI elements.

Package config handles user inputs/UI elements.

Index

Constants

View Source
const (

	// ModTimeFormat is the expected modtime format
	ModTimeFormat = time.RFC3339

	// TimeWindowSpan indicates the delineation between start -> end (start:end)
	TimeWindowSpan = ":"
	// NoColorFlag is the common color disable flag
	NoColorFlag = "NO_COLOR"
)

Variables

View Source
var (

	// ConfigXDG is the offset to the config for XDG
	ConfigXDG = configDirFile
	// ConfigHome is the offset to the config HOME
	ConfigHome = filepath.Join(".config", configDirFile)
	// ConfigEnv allows overriding the config detection
	ConfigEnv = environmentPrefix + "CONFIG_TOML"
	// YesValue is the string variant of 'Yes' (or true) items
	YesValue = strconv.FormatBool(true)
	// NoValue is the string variant of 'No' (or false) items
	NoValue = strconv.FormatBool(false)
	// TOTPDefaultColorWindow is the default coloring rules for totp
	TOTPDefaultColorWindow = []TimeWindow{{Start: 0, End: 5}, {Start: 30, End: 35}}
	// TOTPDefaultBetween is the default color window as a string
	TOTPDefaultBetween = func() []string {
		var results []string
		for _, w := range TOTPDefaultColorWindow {
			results = append(results, fmt.Sprintf("%d%s%d", w.Start, TimeWindowSpan, w.End))
		}
		return results
	}()
)
View Source
var (
	// EnvFeatureTOTP allows disable TOTP feature
	EnvFeatureTOTP = environmentRegister(EnvironmentBool{
		environmentDefault: newDefaultedEnvironment(true,
			environmentBase{
				key:         featureCategory + "TOTP",
				description: "Enable totp feature.",
			}),
	})
	// EnvFeatureClip allows disabling clipboard feature
	EnvFeatureClip = environmentRegister(EnvironmentBool{
		environmentDefault: newDefaultedEnvironment(true,
			environmentBase{
				key:         featureCategory + "CLIP",
				description: "Enable clipboard feature.",
			}),
	})
	// EnvFeatureColor allows disabling color output
	EnvFeatureColor = environmentRegister(EnvironmentBool{
		environmentDefault: newDefaultedEnvironment(true,
			environmentBase{
				key:         featureCategory + "COLOR",
				description: "Enable terminal color feature.",
			}),
	})
	// EnvJSONHashLength handles the hashing output length
	EnvJSONHashLength = environmentRegister(EnvironmentInt{
		environmentDefault: newDefaultedEnvironment(0,
			environmentBase{
				key:         jsonCategory + "HASH_LENGTH",
				description: fmt.Sprintf("Maximum string length of the JSON value when '%s' mode is set for JSON output.", output.JSONModes.Hash),
			}),
		short:   "hash length",
		canZero: true,
	})
	// EnvReadOnly indicates if in read-only mode
	EnvReadOnly = environmentRegister(EnvironmentBool{
		environmentDefault: newDefaultedEnvironment(false,
			environmentBase{
				key:         "READONLY",
				description: "Operate in readonly mode.",
			}),
	})
	// EnvTOTPTimeout indicates when TOTP display should timeout
	EnvTOTPTimeout = environmentRegister(EnvironmentInt{
		environmentDefault: newDefaultedEnvironment(120,
			environmentBase{
				key:         totpCategory + "TIMEOUT",
				description: "Time, in seconds, to show a TOTP token before automatically exiting.",
			}),
		short: "max totp time",
	})
	// EnvTOTPCheckOnInsert will indicate if TOTP tokens should be check for validity during the insert process
	EnvTOTPCheckOnInsert = environmentRegister(EnvironmentBool{
		environmentDefault: newDefaultedEnvironment(true,
			environmentBase{
				key:         totpCategory + "CHECK_ON_INSERT",
				description: "Test TOTP code generation on insert.",
			}),
	})
	// EnvStore is the location of the keepass file/store
	EnvStore = environmentRegister(EnvironmentString{
		environmentStrings: environmentStrings{
			environmentDefault: newDefaultedEnvironment("",
				environmentBase{
					key:         "STORE",
					description: "The kdbx file to operate on.",
					requirement: "must be set",
				}),
			allowed: []string{fileExample},
			flags:   []stringsFlags{canExpandFlag},
		},
	})
	// EnvClipCopy allows overriding the clipboard copy command
	EnvClipCopy = environmentRegister(EnvironmentArray{
		environmentStrings: environmentStrings{
			environmentDefault: newDefaultedEnvironment("",
				environmentBase{
					key:         clipCategory + "COPY",
					description: "Override the detected platform copy command.",
				}),
			flags: []stringsFlags{isCommandFlag},
		},
	})
	// EnvTOTPColorBetween handles terminal coloring for TOTP windows (seconds)
	EnvTOTPColorBetween = environmentRegister(EnvironmentArray{
		environmentStrings: environmentStrings{
			environmentDefault: newDefaultedEnvironment(strings.Join(TOTPDefaultBetween, arrayDelimiter),
				environmentBase{
					key: totpCategory + "COLOR_WINDOWS",
					description: fmt.Sprintf(`Override when to set totp generated outputs to different colors,
must be a list of one (or more) rules where a '%s' delimits the start and end second (0-60 for each).`, TimeWindowSpan),
				}),
			flags:   []stringsFlags{canDefaultFlag},
			allowed: exampleColorWindows,
		},
	})
	// EnvKeyFile is an keyfile for the database
	EnvKeyFile = environmentRegister(EnvironmentString{
		environmentStrings: environmentStrings{
			environmentDefault: newDefaultedEnvironment("",
				environmentBase{
					key:         credsCategory + "KEY_FILE",
					requirement: requiredKeyOrKeyFile,
					description: "A keyfile to access/protect the database.",
				}),
			allowed: []string{"keyfile"},
			flags:   []stringsFlags{canDefaultFlag, canExpandFlag},
		},
	})
	// EnvDefaultModTime is modtime override ability for entries
	EnvDefaultModTime = environmentRegister(EnvironmentString{
		environmentStrings: environmentStrings{
			environmentDefault: newDefaultedEnvironment("",
				environmentBase{
					key:         defaultCategory + "MODTIME",
					description: fmt.Sprintf("Input modification time to set for the entry\n\nExpected format: %s.", ModTimeFormat),
				}),
			flags:   []stringsFlags{canDefaultFlag},
			allowed: []string{"modtime"},
		},
	})
	// EnvJSONMode controls how JSON is output in the 'data' field
	EnvJSONMode = environmentRegister(EnvironmentString{
		environmentStrings: environmentStrings{
			environmentDefault: newDefaultedEnvironment(string(output.JSONModes.Hash),
				environmentBase{
					key:         jsonCategory + "MODE",
					description: fmt.Sprintf("Changes what the data field in JSON outputs will contain.\n\nUse '%s' with CAUTION.", output.JSONModes.Raw),
				}),
			flags:   []stringsFlags{canDefaultFlag},
			allowed: output.JSONModes.List(),
		},
	})
	// EnvTOTPFormat supports formatting the TOTP tokens for generation of tokens
	EnvTOTPFormat = environmentRegister(EnvironmentFormatter{
		environmentBase: environmentBase{
			key:         totpCategory + "OTP_FORMAT",
			description: "Override the otpauth url used to store totp tokens. It must have ONE format string ('%s') to insert the totp base code.",
		}, fxn: formatterTOTP, allowed: "otpauth//url/%s/args...",
	})
	// EnvPasswordMode indicates how the password is read
	EnvPasswordMode = environmentRegister(EnvironmentString{
		environmentStrings: environmentStrings{
			environmentDefault: newDefaultedEnvironment(string(DefaultKeyMode),
				environmentBase{
					key:         credsCategory + "PASSWORD_MODE",
					requirement: "must be set to a valid mode when using a key",
					description: fmt.Sprintf(`How to retrieve the database store password. Set to '%s' when only using a key file.
Set to '%s' to ignore the set key value`, noKeyMode, IgnoreKeyMode),
				}),
			allowed: []string{string(commandKeyMode), string(IgnoreKeyMode), string(noKeyMode), string(plainKeyMode)},
			flags:   []stringsFlags{canDefaultFlag},
		},
	})
)

Functions

func CanColor

func CanColor() bool

CanColor indicates if colorized output is allowed (or disabled)

func DefaultTOML

func DefaultTOML() (string, error)

DefaultTOML will load the internal, default TOML with additional comment markups

func LoadConfig

func LoadConfig(r io.Reader, loader Loader) error

LoadConfig will read the input reader and use the loader to source configuration files

func LoadConfigFile

func LoadConfigFile(path string) error

LoadConfigFile will load a path as the configuration it will also set the environment

func NewConfigFiles

func NewConfigFiles() []string

NewConfigFiles will get the list of candidate config files

func NewFeatureError added in v1.7.0

func NewFeatureError(name string) error

NewFeatureError creates an error if a feature is not enabled

func TextPositionFields added in v1.5.0

func TextPositionFields() string

TextPositionFields is the displayable set of templated fields

Types

type EnvironmentArray

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

EnvironmentArray is an array of strings variable

func (EnvironmentArray) Get

func (e EnvironmentArray) Get() []string

Get indicates the item should be queried as an array

type EnvironmentBool

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

EnvironmentBool are environment settings that are booleans

func (EnvironmentBool) Get

func (e EnvironmentBool) Get() bool

Get will get the boolean value for the setting

type EnvironmentFormatter

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

EnvironmentFormatter allows for sending a string into a get request

func (EnvironmentFormatter) Get

func (e EnvironmentFormatter) Get(value string) string

Get will retrieve the value with the formatted input included

func (EnvironmentFormatter) Key

func (e EnvironmentFormatter) Key() string

type EnvironmentInt

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

EnvironmentInt are environment settings that are integers

func (EnvironmentInt) Get

func (e EnvironmentInt) Get() (int64, error)

Get will get the integer value for the setting

type EnvironmentString

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

EnvironmentString represents a string variable

func (EnvironmentString) Get

func (e EnvironmentString) Get() string

Get will read the string from the environment

type Key

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

Key is a wrapper to help manage the returned key

func NewKey

func NewKey(defaultKeyModeType KeyModeType) (Key, error)

NewKey will create a new key

func (Key) Read

func (k Key) Read() (string, error)

Read will read the key as configured by the mode

type KeyModeType

type KeyModeType string

KeyModeType are valid ways to get the key

const (

	// IgnoreKeyMode will ignore the value set in the key (acts like no key)
	IgnoreKeyMode KeyModeType = "ignore"

	// DefaultKeyMode is the default operating keymode if NOT set
	DefaultKeyMode = commandKeyMode
)

type Loader

type Loader func(string) (io.Reader, error)

Loader indicates how included files should be sourced

type Position added in v1.5.0

type Position struct {
	Start int
	End   int
}

Position is the start/end of a word in a greater set

type TimeWindow added in v1.5.0

type TimeWindow struct {
	Start int
	End   int
}

TimeWindow for handling terminal colors based on timing

type Word added in v1.5.0

type Word struct {
	Text     string
	Position Position
}

Word is the text and position in a greater position

Directories

Path Synopsis
Package store is the internal memory store for loaded configuration settings
Package store is the internal memory store for loaded configuration settings

Jump to

Keyboard shortcuts

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