util

package
v2.1.111 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AppName is tge application name for logging.
	AppName = "codegen"
)
View Source
const (
	// DefaultErrorExitCode is the default exit code in case of an error
	DefaultErrorExitCode = 1
)

Variables

View Source
var (

	// ErrExit can be used to exit with a non 0 exit code without any error message
	ErrExit = fmt.Errorf("exit")
)

Functions

func AppLogger

func AppLogger() *log.Entry

AppLogger returns the application logger.

func BackupGoModAndGoSum

func BackupGoModAndGoSum() (func(), error)

BackupGoModAndGoSum creates backup copies of go.mod and go.sum and returns a function to run at the end of execution to revert the go.mod and go.sum in the repo to the backups.

func CheckErr

func CheckErr(err error)

CheckErr prints a user friendly error to STDERR and exits with a non-zero exit code.

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the JX_HOME directory, creating it if missing

func CopyDirPreserve

func CopyDirPreserve(src string, dst string) error

CopyDirPreserve copies from the src dir to the dst dir if the file does NOT already exist in dst

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from the specified source src to dst. credit https://gist.github.com/r0l1/92462b38df26839a3ca324697c8cba04

func DeleteDirContents

func DeleteDirContents(dir string) error

DeleteDirContents removes all the contents of the given directory

func DeleteFile

func DeleteFile(fileName string) (err error)

DeleteFile deletes a file from the operating system. This should NOT be used to delete any sensitive information because it can easily be recovered. Use DestroyFile to delete sensitive information

func DirExists

func DirExists(path string) (bool, error)

DirExists checks if path exists and is a directory

func DownloadFile

func DownloadFile(filepath string, url string) (err error)

DownloadFile downloads a file from the given URL

func EnsureGoPath

func EnsureGoPath() error

EnsureGoPath ensures the GOPATH environment variable is set and points to a valid directory.

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if the specified path exist, false otherwise. An error is returned if and file system operation fails.

func GetClientWithTimeout

func GetClientWithTimeout(duration time.Duration) *http.Client

GetClientWithTimeout returns a client with JX default transport and user specified timeout

func GetModuleDir

func GetModuleDir(moduleDir string, targetRequirement string, gopath string) (string, error)

GetModuleDir determines the directory on disk of the specified module dependency. Returns the empty string if the target requirement is not part of the module graph.

func GetModuleRequirements

func GetModuleRequirements(dir string, gopath string) (map[string]map[string]string, error)

GetModuleRequirements returns the requirements for the GO module rooted in dir It returns a map[<module name>]map[<requirement name>]<requirement version>

func GoGet

func GoGet(path string, version string, gopath string, goModules bool, sourceOnly bool, update bool) error

GoGet runs go get to install the specified binary.

func GoPath

func GoPath() string

GoPath returns the first element of the GOPATH. The empty string is returned if GOPATH is not set.

func GoPathBin

func GoPathBin(gopath string) string

GoPathBin returns the bin directory of the first GOPATH element.

func GoPathMod

func GoPathMod(gopath string) string

GoPathMod returns the modules directory of the first GOPATH element.

func GoPathSrc

func GoPathSrc(gopath string) string

GoPathSrc returns the src directory of the first GOPATH element.

func HomeDir

func HomeDir() string

HomeDir returns the users home directory

func InvalidOptionf

func InvalidOptionf(option string, value interface{}, message string, a ...interface{}) error

InvalidOptionf returns an error that shows the invalid option.

func IsolatedGoPath

func IsolatedGoPath() (string, error)

IsolatedGoPath returns the isolated go path for codegen

func JoinMap

func JoinMap(m map[string]string, pairSep string, keyValueSep string) string

func MissingOption

func MissingOption(name string) error

MissingOption reports a missing command line option using the full name expression.

func SetLevel

func SetLevel(s string) error

SetLevel sets the logging level

Types

type Command

type Command struct {
	Errors             []error
	Dir                string
	Name               string
	Args               []string
	ExponentialBackOff *backoff.ExponentialBackOff
	Timeout            time.Duration
	Out                io.Writer
	Err                io.Writer
	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) Run

func (c *Command) Run() (string, error)

Run Execute the command and block waiting for return values

func (*Command) RunWithoutRetry

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

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

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) SetExponentialBackOff

func (c *Command) SetExponentialBackOff(backoff *backoff.ExponentialBackOff)

SetExponentialBackOff Setter method for ExponentialBackOff to enable use of interface instead of Command struct

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) SetTimeout

func (c *Command) SetTimeout(timeout time.Duration)

SetTimeout Setter method for Timeout 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

Jump to

Keyboard shortcuts

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