cfg

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MPL-2.0 Imports: 17 Imported by: 95

Documentation

Index

Constants

View Source
const (
	// XdgConfigDir defines the path to the minimal XDG-compatible configuration directory
	XdgConfigDir = "~/.config/"

	// WtfConfigDirV1 defines the path to the first version of configuration. Do not use this
	WtfConfigDirV1 = "~/.wtf/"

	// WtfConfigDirV2 defines the path to the second version of the configuration. Use this.
	WtfConfigDirV2 = "~/.config/wtf/"

	// WtfConfigFile defines the name of the default config file
	WtfConfigFile = "config.yml"
)

Variables

This section is empty.

Functions

func Copy added in v0.0.10

func Copy(src, dest string) error

Copy copies src to dest, doesn't matter if src is a directory or a file

func CreateFile

func CreateFile(fileName string) (string, error)

CreateFile creates the named file in the config directory, if it does not already exist. If the file exists it does not recreate it. If successful, returns the absolute path to the file If unsuccessful, returns an error

func Initialize added in v0.19.0

func Initialize(hasCustom bool)

Initialize takes care of settings up the initial state of WTF configuration It ensures necessary directories and files exist

func LoadWtfConfigFile added in v0.18.0

func LoadWtfConfigFile(filePath string) *config.Config

LoadWtfConfigFile loads the specified config file

func NewDefaultColorConfig added in v0.24.0

func NewDefaultColorConfig() (*config.Config, error)

NewDefaultColorConfig creates and returns a config.Config-compatible configuration struct using a DefaultColorTheme to pre-populate all the relevant values

func ParseAsMapOrList added in v0.22.0

func ParseAsMapOrList(ymlConfig *config.Config, configKey string) []string

ParseAsMapOrList takes a configuration key and attempts to parse it first as a map and then as a list. Map entries are concatenated as "key/value"

func ParseTimeString added in v0.40.0

func ParseTimeString(cfg *config.Config, configKey string, defaultValue string) time.Duration

ParseTimeString takes a configuration key and attempts to parse it first as an int and then as a duration (int + time unit)

func StoreSecret added in v0.31.0

func StoreSecret(globalConfig *config.Config, secret *Secret) error

func WtfConfigDir added in v0.18.0

func WtfConfigDir() (string, error)

WtfConfigDir returns the absolute path to the configuration directory

Types

type BorderTheme added in v0.24.0

type BorderTheme struct {
	Focusable   string
	Focused     string
	Unfocusable string
}

BorderTheme defines the default color scheme for drawing widget borders

type CheckboxTheme added in v0.24.0

type CheckboxTheme struct {
	Checked string
}

CheckboxTheme defines the default color scheme for drawing checkable rows in widgets

type ColorTheme added in v0.24.0

ColorTheme is an alamgam of all the default color settings

func NewDefaultColorTheme added in v0.24.0

func NewDefaultColorTheme() ColorTheme

NewDefaultColorTheme creates and returns an instance of DefaultColorTheme

type Common added in v0.9.2

type Common struct {
	Module
	PositionSettings `help:"Defines where in the grid this module�s widget will be displayed."`
	Sigils

	Colors ColorTheme
	Config *config.Config

	DocPath string

	Bordered        bool          `help:"Whether or not the module should be displayed with a border." values:"true, false" optional:"true" default:"true"`
	Enabled         bool          `` /* 134-byte string literal not displayed */
	Focusable       bool          `help:"Whether or  not this module is focusable." values:"true, false" optional:"true" default:"false"`
	LanguageTag     string        `` /* 127-byte string literal not displayed */
	RefreshInterval time.Duration `` /* 185-byte string literal not displayed */
	Title           string        `help:"The title string to show when displaying this module" optional:"true"`
	// contains filtered or unexported fields
}

Common defines a set of common configuration settings applicable to all modules

func NewCommonSettingsFromModule added in v0.9.2

func NewCommonSettingsFromModule(name, defaultTitle string, defaultFocusable bool, moduleConfig *config.Config, globalConfig *config.Config) *Common

NewCommonSettingsFromModule returns a common settings configuration tailed to the given module

func (*Common) DefaultFocusedRowColor added in v0.14.0

func (common *Common) DefaultFocusedRowColor() string

func (*Common) DefaultRowColor added in v0.9.2

func (common *Common) DefaultRowColor() string

func (*Common) FocusChar added in v0.9.2

func (common *Common) FocusChar() string

FocusChar returns the keyboard number assigned to the widget used to give onscreen focus to this widget, as a string. Focus characters can be a range between 1 and 9

func (*Common) LocalizedPrinter added in v0.35.0

func (common *Common) LocalizedPrinter() (*message.Printer, error)

LocalizedPrinter returns a message.Printer instance localized to the BCP 47 language configuration value defined in 'wtf.language' config. If none exists, it defaults to 'en-CA'. Use this to format numbers, etc.

func (*Common) PaginationMarker added in v0.35.0

func (common *Common) PaginationMarker(length, pos, width int) string

PaginationMarker generates the pagination indicators that appear in the top-right corner of multisource widgets

func (*Common) RightAlignFormat added in v0.9.2

func (common *Common) RightAlignFormat(width int) string

func (*Common) RowColor added in v0.9.2

func (common *Common) RowColor(idx int) string

func (*Common) SetDocumentationPath added in v0.35.0

func (common *Common) SetDocumentationPath(path string)

SetDocumentationPath is used to explicitly set the documentation path that should be opened when the key to open the documentation is pressed. Setting this is probably not necessary unless the module documentation is nested inside a documentation subdirectory in the /wtfutildocs repo, or the module here has a different name than the module's display name in the documentation (which ideally wouldn't be a thing).

func (*Common) Validations added in v0.14.0

func (common *Common) Validations() []Validatable

Validations aggregates all the validations from all the sub-sections in Common into a single array of validations

type Module added in v0.9.2

type Module struct {
	Name string
	Type string
}

type PositionSettings added in v0.14.0

type PositionSettings struct {
	Validations *Validations

	Height int
	Left   int
	Top    int
	Width  int
}

PositionSettings represents the onscreen location of a widget

func NewPositionSettingsFromYAML added in v0.14.0

func NewPositionSettingsFromYAML(moduleConfig *config.Config) PositionSettings

NewPositionSettingsFromYAML creates and returns a new instance of cfg.Position

type RowTheme added in v0.24.0

type RowTheme struct {
	EvenBackground string
	EvenForeground string

	OddBackground string
	OddForeground string

	HighlightedBackground string
	HighlightedForeground string
}

RowTheme defines the default color scheme for row text

type Secret added in v0.31.0

type Secret struct {
	Service  string
	Secret   string
	Username string
	Store    string
}

func FetchSecret added in v0.31.0

func FetchSecret(globalConfig *config.Config, service string) (*Secret, error)

Fetch secret for `service`. Service is customarily a URL, but can be any identifier uniquely used by wtf to identify the service, such as the name of the module. nil is returned if the secretStore global property is not present or the secret is not found in that store.

type SecretLoadParams added in v0.31.0

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

func ModuleSecret added in v0.31.0

func ModuleSecret(name string, globalConfig *config.Config, secret *string) *SecretLoadParams

Load module secrets.

The credential helpers impose this structure:

SERVICE is mapped to a SECRET and USERNAME

Only SECRET is secret, SERVICE and USERNAME are not, so this API doesn't expose USERNAME.

SERVICE was intended to be the URL of an API server, but for hosted services that do not have or need a configurable API server, its easier to just use the module name as the SERVICE:

   cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load()

The user will use the module name as the service, and the API key as
the secret, for example:

   % wtfutil save-secret circleci
   Secret: ...

If a module (such as pihole, jenkins, or github) might have multiple instantiations each using a different API service (with its own unique API key), then the module should use the API URL to lookup the secret. For example, for github:

cfg.ModuleSecret(name, globalConfig, &settings.apiKey).
    Service(settings.baseURL).
    Load()

The user will use the API URL as the service, and the API key as the secret, for example, with github configured as:

   -- config.yml
   mods:
     github:
       baseURL: "https://github.mycompany.com/api/v3"
       ...

the secret must be saved as:

   % wtfutil save-secret https://github.mycompany.com/api/v3
   Secret: ...

If baseURL is not set in the configuration it will be the modules
default, and the SERVICE will default to the module name, "github",
and the user must save the secret as:

   % wtfutil save-secret github
   Secret: ...

Ideally, the individual module documentation would describe the
SERVICE name to use to save the secret.

func (*SecretLoadParams) Load added in v0.31.0

func (slp *SecretLoadParams) Load()

func (*SecretLoadParams) Service added in v0.31.0

func (slp *SecretLoadParams) Service(service string) *SecretLoadParams

type Sigils added in v0.9.2

type Sigils struct {
	Checkbox struct {
		Checked   string
		Unchecked string
	}
	Paging struct {
		Normal   string
		Selected string
	}
}

type TextTheme added in v0.24.0

type TextTheme struct {
	Label      string
	Subheading string
	Text       string
	Title      string
}

TextTheme defines the default color scheme for text rendering

type Validatable added in v0.14.0

type Validatable interface {
	Error() error
	HasError() bool
	String() string
	IntValue() int
}

Validatable is implemented by any value that validates a configuration setting

type Validations added in v0.14.0

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

Validations represent a collection of config setting validations

func NewValidations added in v0.14.0

func NewValidations() *Validations

NewValidations creates and returns an instance of Validations

type WidgetTheme added in v0.24.0

type WidgetTheme struct {
	Background string
}

WidgetTheme defines the default color scheme for the widget rect itself

Jump to

Keyboard shortcuts

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