util

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: Apache-2.0 Imports: 15 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 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 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 MYSQL_PWD or STDIN; enable debug logging.

func PromptPassword

func PromptPassword() (string, error)

PromptPassword reads a password from STDIN without echoing the typed characters. Requires that STDIN is a TTY.

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.

Types

type ShellOut

type ShellOut struct {
	Command          string
	PrintableCommand string        // Used in String() if non-empty; useful for hiding passwords in output
	Dir              string        // Initial working dir for the command if non-empty
	Timeout          time.Duration // If > 0, kill process after this amount of time
	CombineOutput    bool          // If true, combine stdout and stderr into a single stream
	// contains filtered or unexported fields
}

ShellOut represents a command-line for an external command, executed via sh -c

func NewInterpolatedShellOut

func NewInterpolatedShellOut(command string, variables map[string]string) (*ShellOut, error)

NewInterpolatedShellOut takes a shell command-line containing variables of format {VARNAME}, and performs substitution on them based on the supplied map of variable names to values.

Variable names should be supplied in all-caps in the variables map. Inside of command, they are case-insensitive. If any unknown variable is contained in the command string, a non-nil error will be returned and the unknown variable will not be interpolated.

As a special case, any variable name may appear with an X suffix. This will still be replaced as normal in the generated ShellOut.Command, but will appear as all X's in ShellOut.PrintableCommand. For example, if the command string contains "{PASSWORDX}" and variables has a key "PASSWORD", it will be replaced in a manner that obfuscates the actual password in PrintableCommand.

func (*ShellOut) Run

func (s *ShellOut) Run() error

Run shells out to the external command and blocks until it completes. It returns an error if one occurred. STDIN, STDOUT, and STDERR will be redirected to those of the parent process.

func (*ShellOut) RunCapture

func (s *ShellOut) RunCapture() (string, error)

RunCapture shells out to the external command and blocks until it completes. It returns the command's STDOUT output as a single string, optionally with STDERR if CombineOutput is true; otherwise STDERR is redirected to that of the parent process. STDIN is always redirected from the parent process.

func (*ShellOut) RunCaptureSplit

func (s *ShellOut) RunCaptureSplit() ([]string, error)

RunCaptureSplit behaves like RunCapture, except the output will be tokenized. If newlines are present in the output, it will be split on newlines; else if commas are present, it will be split on commas; else ditto for tabs; else ditto for spaces. Blank tokens will be ignored (i.e. 2 delimiters in a row get treated as a single delimiter; leading or trailing delimiter is ignored). Does NOT provide any special treatment for quoted fields in the output.

func (*ShellOut) String

func (s *ShellOut) String() string

Jump to

Keyboard shortcuts

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