settings

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package persistence manages the persistent user profile used by the command application infrastructure. This includes automatically reading any profile in as part of startup, and of updating the profile as needed.

Index

Constants

View Source
const ProfileDirectory = ".org.fernwood"

ProfileDirectory is the name of the invisible directory that is created in the user's home directory to host configuration data.

Variables

View Source
var Configurations map[string]Configuration

Configurations is a map keyed by the configuration name for each configuration in the config file.

View Source
var DefaultConfiguration = i18n.L("Default.configuration")

DefaultConfiguration is a localized string that contains the local text for "Default configuration".

View Source
var ProfileDirty = false

ProfileDirty is set to true when a key value is written or deleted, which tells us to rewrite the profile. If false, then no update is required.

View Source
var ProfileFile = "config.json"

ProfileFile is the name of the configuration file that contains the profiles.

View Source
var ProfileName = "default"

ProfileName is the name of the configuration being used. The default configuration is always named "default".

Functions

func Delete

func Delete(key string) error

Delete removes a key from the map entirely. Also removes if from the active defaults.

func DeleteProfile

func DeleteProfile(key string) error

func Exists

func Exists(key string) bool

Exists test to see if a key value exists or not.

func Get

func Get(key string) string

Get gets a profile entry in the current configuration structure. If the key does not exist, an empty string is returned.

func GetBool

func GetBool(key string) bool

GetBool returns the boolean value of a profile string. If the string is "Y", "YES", "1", or "true" then the value returns true.

func GetInt

func GetInt(key string) int

GetInt returns the integer value of a profile string.

func GetUsingList

func GetUsingList(key string, values ...string) int

Get a key value, and compare it to a list of provided values. If it matches one of the items in the list, then the position in the list (one-based) is returned. If the value is not in the list at all, a result of 0 is returned.

func Keys

func Keys() []string

Keys returns the list of keys in the profile as an array of strings.

func Load

func Load(application string, name string) error

Load reads in the named profile, if it exists.

func Save

func Save() error

Save the current configuration.

func Set

func Set(key string, value string)

Set puts a profile entry in the current Configuration structure.

func SetDefault

func SetDefault(key string, value string)

SetDefault puts a profile entry in the current Configuration structure. It is different than Set() in that it doesn't mark the value as dirty, so no need to update on account of this setting.

func UseProfile

func UseProfile(name string)

UseProfile specifies the name of the profile to use, if other than the default.

Types

type Configuration

type Configuration struct {
	Description string            `json:"description,omitempty"`
	ID          string            `json:"id,omitempty"`
	Items       map[string]string `json:"items"`
}

Configuration describes what is known about a configuration.

var CurrentConfiguration *Configuration

CurrentConfiguration describes the current configuration that is active.

Jump to

Keyboard shortcuts

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