config

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: LGPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package config handles the user configations.

nolint:goconst

Example (Recommend)
color.Enable = false
fmt.Print(recommend(""))
Output:

(suggestion: do not use)
Example (UpdateBool)
color.Enable = false
updateBool(false, "example")
Output:

The example is not in use.
Example (UpdateString)
color.Enable = false
updateString("", "example", "")
updateString("x", saveDir, "")
Output:

The empty example setting is not in use.

  The save-directory is set to "". ✗

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrEditorNil = errors.New("no suitable text editor can be found")
	ErrEditorRun = errors.New("editor cannot be run")
	ErrSaveType  = errors.New("save value type is unsupported")
	ErrBool      = errors.New("key is not a boolean (true/false) value")
	ErrString    = errors.New("key is not a string (text) value")
	ErrUint      = errors.New("key is not a absolute number")
)

Functions

func ColorCSS added in v0.0.31

func ColorCSS(elm string) string

ColorCSS returns the element colored using CSS syntax highlights.

func ColorHTML added in v0.0.31

func ColorHTML(elm string) string

ColorHTML returns the element colored using HTML syntax highlights.

func Create

func Create(name string, ow bool) error

Create a named configuration file with the option to overwrite any existing files.

func CtrlC added in v0.0.33

func CtrlC()

CtrlC intercepts Ctrl-C key combinations to exit out of the Setup.

func Delete

func Delete() error

Delete a configuration file.

func Edit

func Edit() error

Edit a configuration file.

func Editor

func Editor() string

Editor returns the path of a configured or discovered text editor.

func Enabled

func Enabled() map[string]interface{}

Enabled returns all the Viper keys holding a value that are used. This will hide all unrecognized manual edits to the configuration file.

func Info

func Info(style string) error

Info prints the content of a configuration file.

func InitDefaults

func InitDefaults()

InitDefaults initializes flag and configuration defaults.

func KeySort added in v0.0.33

func KeySort() []string

KeySort list all the available configuration setting names sorted by hand.

func Keys

func Keys() []string

Keys list all the available configuration setting names sorted alphabetically.

func List

func List() error

List and print all the available configurations.

func Location added in v0.0.33

func Location() string

Location returns the absolute path of the current configuration file and the status of any missing settings.

func Marshal

func Marshal() (interface{}, error)

Marshal default values for use in a YAML configuration file.

func Missing

func Missing() (list []string)

Missing returns the settings that are not found in the configuration file. This could be due to new features being added after the file was generated or because of manual file edits.

func Names

func Names(lexer string) string

Names returns the chroma style names.

func New added in v0.0.33

func New(overwrite bool) error

New creates a new configuration file and prints the results.

func Path

func Path() string

Path returns the absolute path of the configuration file.

func Set

func Set(name string)

Set edits and saves a named setting within a configuration file. It also accepts numeric index values printed by List().

func SetConfig

func SetConfig(flag string) error

SetConfig reads and loads a configuration file.

func Setup

func Setup(start int)

Setup walks through all the settings and saves them to the configuration file. Start the walk through at the provided question number or leave it at 0.

func Update

func Update(name string, setup bool)

Update edits and saves a named setting within a configuration file.

func UpdateConfig

func UpdateConfig(name string, stdout bool) error

UpdateConfig saves all viper settings to the named file.

func Validate

func Validate(key string) (ok bool)

Validate the existence of the key in a list of settings.

Types

type Defaults

type Defaults map[string]interface{}

Defaults for setting keys.

func Reset added in v0.0.31

func Reset() Defaults

Reset configuration values. These are the default values whenever a setting is deleted, or when a new configuration file is created.

type Formats

type Formats struct {
	Info [5]string
}

Formats choices for flags.

func Format

func Format() Formats

Format flag choices for the info command.

type Hints

type Hints map[string]string

Hints for configuration values.

func Tip added in v0.0.31

func Tip() Hints

Tip provides a brief help on the config file configurations.

type Settings

type Settings struct {
	Editor string
	HTML   struct {
		Font struct {
			Embed  bool   `yaml:"embed"`
			Family string `yaml:"family"`
			Size   string `yaml:"size"`
		}
		Layout string `yaml:"layout"`
		Meta   struct {
			Author      string `yaml:"author"`
			ColorScheme string `yaml:"color-scheme"`
			Description string `yaml:"description"`
			Keywords    string `yaml:"keywords"`
			Referrer    string `yaml:"referrer"`
			Robots      string `yaml:"robots"`
			ThemeColor  string `yaml:"theme-color"`
			Generator   bool   `yaml:"generator"`
			Notranslate bool   `yaml:"notranslate"`
			RetroTxt    bool   `yaml:"retrotxt"`
		}
		Title string `yaml:"title"`
	}
	SaveDirectory string `yaml:"save-directory"`
	ServerPort    uint   `yaml:"serve"`
	Style         struct {
		Info string `yaml:"info"`
		HTML string `yaml:"html"`
	}
}

Settings types and names to be saved as YAML.

Jump to

Keyboard shortcuts

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