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
- Variables
- func CanColor() bool
- func DefaultTOML() (string, error)
- func LoadConfig(r io.Reader, loader Loader) error
- func LoadConfigFile(path string) error
- func NewConfigFiles() []string
- func NewFeatureError(name string) error
- func TextPositionFields() string
- type EnvironmentArray
- type EnvironmentBool
- type EnvironmentFormatter
- type EnvironmentInt
- type EnvironmentString
- type Key
- type KeyModeType
- type Loader
- type Position
- type TimeWindow
- type Word
Constants ¶
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 ¶
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 }() )
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 ¶
DefaultTOML will load the internal, default TOML with additional comment markups
func LoadConfig ¶
LoadConfig will read the input reader and use the loader to source configuration files
func LoadConfigFile ¶
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
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
type EnvironmentBool ¶
type EnvironmentBool struct {
// contains filtered or unexported fields
}
EnvironmentBool are environment settings that are booleans
type EnvironmentFormatter ¶
type EnvironmentFormatter struct {
// contains filtered or unexported fields
}
EnvironmentFormatter allows for sending a string into a get request
type EnvironmentInt ¶
type EnvironmentInt struct {
// contains filtered or unexported fields
}
EnvironmentInt are environment settings that are integers
type EnvironmentString ¶
type EnvironmentString struct {
// contains filtered or unexported fields
}
EnvironmentString represents a string variable
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key is a wrapper to help manage the returned key
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 TimeWindow ¶ added in v1.5.0
TimeWindow for handling terminal colors based on timing