util

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FormatUnknown represents an unknown data format
	FormatUnknown = iota

	// FormatText represents a raw string
	FormatText

	// FormatJSON represents data formatted as JSON
	FormatJSON

	// FormatYaml represents data formatted as YAML
	FormatYaml
)

Variables

This section is empty.

Functions

func CallSudo

func CallSudo(action string, params ...string) error

CallSudo asks the user for superuser permissions, and then executes the currently-running program with those permissions for a particular action. TryHandleSudo should be called at the beginning of the program's main() function to catch these sudo calls.

func CliChoice added in v1.1.1

func CliChoice(question string, choices []string) (int, error)

CliChoice provides an interactive UI to select between one or more choices

func CliQuestion

func CliQuestion(question string) string

CliQuestion prints a prompt to stdout and reads a line of input from stdin, returning that read string

func CliQuestionHidden

func CliQuestionHidden(question string) (string, error)

CliQuestionHidden prints a prompt to stdout and reads a hidden line of input from stdin. This is meant to be used for passwords where you don't want them printed to the screen

func CliQuestionYesNo

func CliQuestionYesNo(question string) bool

CliQuestionYesNo prints a question prompt and allows either yes or no answers to be entered, returning "y" or "yes" as true and "n" or "no" as false

func CliQuestionYesNoDefault

func CliQuestionYesNoDefault(question string, defaultValue bool) bool

CliQuestionYesNoDefault prints a question prompt and allows either yes or no answers to be entered, or no answer at all. If no answer is entered, the defaultValue is returned, otherwise "y" or "yes" returns true and "n" or "no" returns false

func FormatData

func FormatData(data interface{}, format int) (string, error)

FormatData formats the given value with the given format

func FormatToName

func FormatToName(format int) string

FormatToName returns a text representation of a format code

func GetAutoUpdate added in v1.1.1

func GetAutoUpdate() (bool, error)

GetAutoUpdate gets if automatic updates are enabled

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir gets the os-dependent user configuration directory

func IsMissingData

func IsMissingData(err error) bool

IsMissingData returns true if the error is a missingDataError

func LoadConfig

func LoadConfig(config string, data interface{}) error

LoadConfig loads a user config file of the given name

func LoadExternalConfig

func LoadExternalConfig(filename string, data interface{}) error

LoadExternalConfig reads an external config file, outside of the default user config directory

func LoadUserAuth

func LoadUserAuth() error

LoadUserAuth loads the default user auth config

func MergeAuth

func MergeAuth(base *types.RootAuth, overlay *types.RootAuth)

MergeAuth merges an overlay RootAuth into a base RootAuth

func NameToFormat

func NameToFormat(name string) int

NameToFormat returns a number representation of a format name

func ParseData

func ParseData(data []byte, format int) (interface{}, error)

ParseData parses a string of bytes into the given format

func SaveConfig

func SaveConfig(config string, data interface{}) error

SaveConfig saves a user config file of the given name

func SaveExternalConfig added in v1.1.1

func SaveExternalConfig(filename string, data interface{}) error

SaveExternalConfig saves a file outside of the default user config directory

func SaveUserAuth

func SaveUserAuth() error

SaveUserAuth saves the default user auth config

func SetAtPath

func SetAtPath(data *interface{}, path *[]interface{}, newData interface{}) error

SetAtPath is the write equivalent of TraversePath. It will write a subset of the given value with the given new data at the provided path. It will also create maps and arrays to reach the provided path if they don't exist, as well as filling out arrays with null values to make them long enough to fit a given path segment.

func SetAutoUpdate added in v1.1.1

func SetAutoUpdate(shouldAutoUpdate bool) (bool, error)

SetAutoUpdate configures if automatic updates are enabled

func TraversePath

func TraversePath(data interface{}, path *[]interface{}) (interface{}, error)

TraversePath takes a JSON-like value and recursively traverses it with a given list of keys. The result is a subset of that input value or an error

func TryAutoUpdateSelf

func TryAutoUpdateSelf() error

TryAutoUpdateSelf checks for an update and replaces the existing executable with the new version if there is one. Update checks are debounced to every 24 hours, and can be disabled with a config option.

func TryHandleSudo

func TryHandleSudo()

TryHandleSudo catches superuser self-executions to do certain actions that require superuser permissions

func TryManualUpdate

func TryManualUpdate() error

TryManualUpdate checks for an update and replaces the existing executable with the new version if there is one. This will always run, without any debouncing or config options to disable it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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