projutil

package
v0.10.1-0...-fa89fd1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GoPathEnv  = "GOPATH"
	GoFlagsEnv = "GOFLAGS"
	GoModEnv   = "GO111MODULE"
	SrcDir     = "src"
)

Variables

View Source
var ErrNoDepManager = fmt.Errorf(`no valid dependency manager file found; dep manager must be one of ["%v", "%v"]`, DepManagerDep, DepManagerGoMod)

Functions

func CheckDepManagerWithRepo

func CheckDepManagerWithRepo(dm DepManagerType, repo string) error

CheckDepManagerWithRepo ensures dependency manager type and repo are being used in combination correctly, as different dependency managers have different Go environment requirements.

func CheckGoProjectCmd

func CheckGoProjectCmd(cmd *cobra.Command) error

func CheckProjectRoot

func CheckProjectRoot() error

CheckProjectRoot checks if the current dir is the project root, and returns an error if not.

func ExecCmd

func ExecCmd(cmd *exec.Cmd) error

func GetGoPkg

func GetGoPkg() string

GetGoPkg returns the current directory's import path by parsing it from wd if this project's repository path is rooted under $GOPATH/src, or from go.mod the project uses Go modules to manage dependencies.

Example: "github.com/example-inc/app-operator"

func GoBuild

func GoBuild(opts GoCmdOptions) error

GoBuild runs "go build" configured with opts.

func GoCmd

func GoCmd(cmd string, opts GoCmdOptions) error

GoCmd runs "go {cmd}".

func GoModOn

func GoModOn() (bool, error)

From https://github.com/golang/go/wiki/Modules:

You can activate module support in one of two ways:
- Invoke the go command in a directory outside of the $GOPATH/src tree,
	with a valid go.mod file in the current directory or any parent of it and
	the environment variable GO111MODULE unset (or explicitly set to auto).
- Invoke the go command with GO111MODULE=on environment variable set.

GoModOn returns true if Go modules are on in one of the above two ways.

func GoTest

func GoTest(opts GoTestOptions) error

GoTest runs "go test" configured with opts.

func IsDepManagerDep

func IsDepManagerDep() bool

func IsDepManagerGoMod

func IsDepManagerGoMod() bool

func IsOperatorAnsible

func IsOperatorAnsible() bool

func IsOperatorGo

func IsOperatorGo() bool

func IsOperatorHelm

func IsOperatorHelm() bool

func MustGetGopath

func MustGetGopath() string

MustGetGopath gets GOPATH and ensures it is set and non-empty. If GOPATH is not set or empty, MustGetGopath exits.

func MustGetwd

func MustGetwd() string

func MustInProjectRoot

func MustInProjectRoot()

MustInProjectRoot checks if the current dir is the project root, and exits if not.

func MustSetWdGopath

func MustSetWdGopath(currentGopath string) string

MustSetWdGopath sets GOPATH to the first element of the path list in currentGopath that prefixes the wd, then returns the set path. If GOPATH cannot be set, MustSetWdGopath exits.

func SetGoVerbose

func SetGoVerbose() error

SetGoVerbose sets GOFLAGS="${GOFLAGS} -v" if GOFLAGS does not already contain "-v" to make "go" command output verbose.

func WdInGoPathSrc

func WdInGoPathSrc() (bool, error)

Types

type DepManagerType

type DepManagerType string
const (
	DepManagerGoMod DepManagerType = "modules"
	DepManagerDep   DepManagerType = "dep"
)

func GetDepManagerType

func GetDepManagerType() (DepManagerType, error)

type ErrInvalidDepManager

type ErrInvalidDepManager string

func (ErrInvalidDepManager) Error

func (e ErrInvalidDepManager) Error() string

type ErrUnknownOperatorType

type ErrUnknownOperatorType struct {
	Type string
}

func (ErrUnknownOperatorType) Error

func (e ErrUnknownOperatorType) Error() string

type GoCmdOptions

type GoCmdOptions struct {
	// BinName is the name of the compiled binary, passed to -o.
	BinName string
	// Args are args passed to "go {cmd}", aside from "-o {bin_name}" and
	// test binary args.
	// These apply to build, clean, get, install, list, run, and test.
	Args []string
	// PackagePath is the path to the main (go build) or test (go test) packages.
	PackagePath string
	// Env is a list of environment variables to pass to the cmd;
	// exec.Command.Env is set to this value.
	Env []string
	// Dir is the dir to run "go {cmd}" in; exec.Command.Dir is set to this value.
	Dir string
	// GoMod determines whether to set the "-mod=vendor" flag.
	// If true and ./vendor/ exists, "go {cmd}" will use vendored modules.
	// If false, "go {cmd}" will not use Go modules. This is the default.
	// This applies to build, clean, get, install, list, run, and test.
	GoMod bool
}

GoCmdOptions is the base option set for "go" subcommands.

type GoTestOptions

type GoTestOptions struct {
	GoCmdOptions
	// TestBinaryArgs are args passed to the binary compiled by "go test".
	TestBinaryArgs []string
}

GoTestOptions is the set of options for "go test".

type OperatorType

type OperatorType = string

OperatorType - the type of operator

const (
	// OperatorTypeGo - golang type of operator.
	OperatorTypeGo OperatorType = "go"
	// OperatorTypeAnsible - ansible type of operator.
	OperatorTypeAnsible OperatorType = "ansible"
	// OperatorTypeHelm - helm type of operator.
	OperatorTypeHelm OperatorType = "helm"
	// OperatorTypeUnknown - unknown type of operator.
	OperatorTypeUnknown OperatorType = "unknown"
)

func GetOperatorType

func GetOperatorType() OperatorType

GetOperatorType returns type of operator is in cwd. This function should be called after verifying the user is in project root.

Jump to

Keyboard shortcuts

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