util

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddGlobalConfigFiles

func AddGlobalConfigFiles(cfg *mybase.Config)

AddGlobalConfigFiles takes the mybase.Config generated from the CLI and adds global option files as sources.

func AddGlobalOptions

func AddGlobalOptions(cmd *mybase.Command)

AddGlobalOptions adds Skeema global options to the supplied mybase.Command. Typically cmd should be the top-level Command / Command Suite.

func CloseCachedConnectionPools

func CloseCachedConnectionPools()

CloseCachedConnectionPools closes all connection pools in all cached Instances that were created via NewInstance.

func FlushInstanceCache

func FlushInstanceCache()

FlushInstanceCache closes all connection pools in all cached Instances that were created via NewInstance, and then flushes the cache entirely.

func IgnorePatterns added in v1.9.0

func IgnorePatterns(cfg *mybase.Config) ([]tengo.ObjectPattern, error)

IgnorePatterns compiles the regexes in the supplied mybase.Config's ignore-* options. If all supplied regex strings were valid, a slice of tengo.ObjectPattern is returned; otherwise, an error with the first invalid regex is returned.

func InteractivePasswordInput added in v1.9.0

func InteractivePasswordInput() (string, error)

InteractivePasswordInput reads a password from STDIN. This only works if STDIN is a terminal.

func NewInstance

func NewInstance(driver, dsn string) (*tengo.Instance, error)

NewInstance wraps tengo.NewInstance such that two identical requests will return the same *tengo.Instance. This helps reduce excessive creation of redundant connections.

func NoInteractiveInput added in v1.9.0

func NoInteractiveInput() (string, error)

NoInteractiveInput always returns an error instead of attempting to read a password.

func ProcessSpecialGlobalOptions

func ProcessSpecialGlobalOptions(cfg *mybase.Config) error

ProcessSpecialGlobalOptions performs special handling of global options with unusual semantics -- handling restricted placement of host and schema; obtaining a password from STDIN if requested; enable debug logging.

func PromptPassword

func PromptPassword(promptArgs ...interface{}) (string, error)

PromptPassword reads a password from STDIN without echoing the typed characters. Requires that STDIN is a TTY. Optionally supply args to build a custom prompt string; first arg must be a string if so, with args behaving like those to fmt.Printf(). The prompt will be written to STDERR, unless STDERR is a non-terminal and STDOUT is a terminal, in which case STDOUT is used.

func RealConnectOptions

func RealConnectOptions(connectOpts string) (string, error)

RealConnectOptions takes a comma-separated string of connection options, strips any Go driver-specific ones, and then returns the new string which is now suitable for passing to an external tool.

func SplitConnectOptions

func SplitConnectOptions(connectOpts string) (map[string]string, error)

SplitConnectOptions takes a string containing a comma-separated list of connection options (typically obtained from the "connect-options" option) and splits them into a map of individual key: value strings. This function understands single-quoted values may contain commas, and will properly treat them not as delimiters. Single-quoted values may also include escaped single quotes, and values in general may contain escaped commas; these are all also treated properly.

func StderrIsTerminal added in v1.10.0

func StderrIsTerminal() bool

StderrIsTerminal returns true if os.Stderr is a terminal.

func StdinIsTerminal added in v1.10.0

func StdinIsTerminal() bool

StdinIsTerminal returns true if os.Stdin is a terminal.

func StdoutIsTerminal added in v1.10.0

func StdoutIsTerminal() bool

StdoutIsTerminal returns true if os.Stdout is a terminal.

func TerminalWidth added in v1.5.3

func TerminalWidth(fd int) (int, error)

TerminalWidth returns the width of the supplied file descriptor if it is a terminal. Otherwise, 0 and an error are returned.

func WrapStringWithPadding added in v1.5.3

func WrapStringWithPadding(s string, lim int, padder string) string

WrapStringWithPadding performs word-wrapping at the given width limit, prepending the supplied padder string to each line after the first. The padder string's width is accounted for in the word-wrapping, on all lines (including the first, even though padding is not applied here to it.) To also pad the first line, prepend the padding to the *return value* of this function; this permits using a different header/padding on the first line if desired. If lim isn't larger than the length of padder, s is returned unchanged. Passing a zero or negative lim safely makes this function a no-op.

Types

type PasswordInputSource added in v1.9.0

type PasswordInputSource func() (string, error)

PasswordInputSource is a function that can be used to obtain a password interactively.

var PasswordPromptInput PasswordInputSource

PasswordPromptInput is the input source used by PromptPassword to obtain a password interactively, or to mock such an input for testing purposes.

func NewMockPasswordInput added in v1.9.0

func NewMockPasswordInput(mockPassword string) PasswordInputSource

NewMockPasswordInput returns a PasswordInputSource function which always returns the specified string.

Jump to

Keyboard shortcuts

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