util

package
v0.0.0-...-95f6ed8 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InfoColor    = "\033[1;32m%s\033[0m"
	WarningColor = "\033[1;33m%s\033[0m"
	StatusColor  = "\033[1;34m%s\033[0m"
	ErrorColor   = "\033[1;31m%s\033[0m"
)

Functions

func ColorAnswer

func ColorAnswer(in string) string

ColorAnswer returns a new function that returns status-colorized (blue) strings for the given arguments with fmt.Sprint().

func ColorError

func ColorError(in string) string

ColorError returns a new function that returns error-colorized (red) strings for the given arguments with fmt.Sprint().

func ColorInfo

func ColorInfo(in string) string

ColorInfo returns a new function that returns info-colorized (green) strings for the given arguments with fmt.Sprint().

func ColorWarning

func ColorWarning(in string) string

ColorWarning returns a new function that returns warning-colorized (yellow) strings for the given arguments with fmt.Sprint().

func ConfigDir

func ConfigDir() string

func CreateConfigPath

func CreateConfigPath(configPath, configFile string) *string

func DxBinaryLocation

func DxBinaryLocation() (string, error)

func DxConfigFile

func DxConfigFile() string

func FileExists

func FileExists(path string) (bool, error)

FileExists checks if path exists and is a file.

func GetColor

func GetColor(optionName string, colorNames []string) (*color.Color, error)

GetColor returns the color for the list of colour names and option name.

func GhConfigDir

func GhConfigDir() string

func HomeDir

func HomeDir() string

func ReadFile

func ReadFile(fn string) ([]byte, error)

func SafeIfAboveZero

func SafeIfAboveZero(number int) string

func SafeTime

func SafeTime(in *time.Time) string

func Strip

func Strip(str string) string

func TrimTemplate

func TrimTemplate(instanceTemplate string, instanceType string) string

Types

type Command

type Command struct {
	Errors []error
	Dir    string
	Name   string
	Args   []string
	Out    io.Writer
	Err    io.Writer
	In     io.Reader
	Env    map[string]string
	// contains filtered or unexported fields
}

Command is a struct containing the details of an external command to be executed.

func (*Command) Attempts

func (c *Command) Attempts() int

Attempts The number of times the command has been executed.

func (*Command) CurrentArgs

func (c *Command) CurrentArgs() []string

CurrentArgs returns the current command arguments.

func (*Command) CurrentDir

func (c *Command) CurrentDir() string

CurrentDir returns the current Dir.

func (*Command) CurrentEnv

func (c *Command) CurrentEnv() map[string]string

CurrentEnv returns the current environment variables.

func (*Command) CurrentName

func (c *Command) CurrentName() string

CurrentName returns the current name of the command.

func (*Command) DidError

func (c *Command) DidError() bool

DidError returns a boolean if any error occurred in any execution of the command.

func (*Command) DidFail

func (c *Command) DidFail() bool

DidFail returns a boolean if the command could not complete (errored on every attempt).

func (*Command) Error

func (c *Command) Error() error

Error returns the last error.

func (*Command) SetArgs

func (c *Command) SetArgs(args []string)

SetArgs Setter method for Args to enable use of interface instead of Command struct.

func (*Command) SetDir

func (c *Command) SetDir(dir string)

SetDir Setter method for Dir to enable use of interface instead of Command struct.

func (*Command) SetEnv

func (c *Command) SetEnv(env map[string]string)

SetEnv Setter method for Env to enable use of interface instead of Command struct.

func (*Command) SetEnvVariable

func (c *Command) SetEnvVariable(name string, value string)

SetEnvVariable sets an environment variable into the environment.

func (*Command) SetName

func (c *Command) SetName(name string)

SetName Setter method for Name to enable use of interface instead of Command struct.

func (*Command) String

func (c *Command) String() string

type CommandError

type CommandError struct {
	Command Command
	Output  string
	// contains filtered or unexported fields
}

CommandError is the error object encapsulating an error from a Command.

func (CommandError) Error

func (c CommandError) Error() string

type CommandRunner

type CommandRunner interface {
	RunWithoutRetry(c *Command) (string, error)
}

CommandRunner interface that wraps the RunWithoutRetry function.

type DefaultCommandRunner

type DefaultCommandRunner struct {
}

func (DefaultCommandRunner) RunWithoutRetry

func (d DefaultCommandRunner) RunWithoutRetry(c *Command) (string, error)

RunWithoutRetry Execute the command without retrying on failure and block waiting for return values.

type Tracer

type Tracer struct {
	http.RoundTripper
}

Tracer implements http.RoundTripper. It prints each request and response/error to os.Stderr.

func (*Tracer) RoundTrip

func (t *Tracer) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip calls the nested RoundTripper while printing each request and response/error to os.Stderr on either side of the nested call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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