projutil

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func CheckGoModules added in v0.12.0

func CheckGoModules() error

CheckGoModules ensures that go modules are enabled.

func CheckGoProjectCmd added in v0.5.0

func CheckGoProjectCmd(cmd *cobra.Command) error

func CheckProjectRoot added in v0.9.0

func CheckProjectRoot() error

CheckProjectRoot checks if the current dir is the project root, and returns an error if not. "build/Dockerfile" may not be present in all projects todo: scaffold Project file for Ansible and Helm with the type information

func CheckRepo added in v0.12.0

func CheckRepo(repo string) error

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

func ExecCmd added in v0.4.0

func ExecCmd(cmd *exec.Cmd) error

func GetGoPkg added in v0.9.0

func GetGoPkg() string

TODO(hasbro17): If this function is called in the subdir of a module project it will fail to parse go.mod and return the correct import path. This needs to be fixed to return the pkg import path for any subdir in order for `generate csv` to correctly form pkg imports for API pkg paths that are not relative to the root dir. This might not be fixable since there is no good way to get the project root from inside the subdir of a module project.

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. If the project has a go.mod then wd must be the project root.

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

func GetOptionalInput added in v0.18.0

func GetOptionalInput(msg string) string

func GetRequiredInput added in v0.18.0

func GetRequiredInput(msg string) string

func GetStringArray added in v0.18.0

func GetStringArray(msg string) []string

func GoBuild added in v0.8.0

func GoBuild(opts GoCmdOptions) error

GoBuild runs "go build" configured with opts.

func GoCmd added in v0.9.0

func GoCmd(cmd string, opts GoCmdOptions) error

GoCmd runs "go {cmd}".

func GoModOn added in v0.8.0

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 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 added in v0.8.0

func GoTest(opts GoTestOptions) error

GoTest runs "go test" configured with opts.

func IsOperatorAnsible added in v0.8.0

func IsOperatorAnsible() bool

func IsOperatorGo added in v0.5.0

func IsOperatorGo() bool

func IsOperatorHelm added in v0.8.0

func IsOperatorHelm() bool

func MustGetGopath added in v0.5.0

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 added in v0.9.0

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 PrintDeprecationWarning added in v0.17.0

func PrintDeprecationWarning(msg string)

PrintDeprecationWarning prints a colored warning wrapping msg to the terminal.

func RewriteFileContents added in v0.18.0

func RewriteFileContents(filename, instruction, content string) error

RewriteFileContents adds the provided content before the last occurrence of the word label and rewrites the file with the new content.

func SetGoVerbose added in v0.8.0

func SetGoVerbose() error

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

func WdInGoPathSrc added in v0.9.0

func WdInGoPathSrc() (bool, error)

Types

type ErrUnknownOperatorType added in v0.8.0

type ErrUnknownOperatorType struct {
	Type string
}

func (ErrUnknownOperatorType) Error added in v0.8.0

func (e ErrUnknownOperatorType) Error() string

type GoCmdOptions added in v0.8.0

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
}

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

type GoTestOptions added in v0.8.0

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 InteractiveLevel added in v0.18.0

type InteractiveLevel int

InteractiveLevel captures the user preference on the generation of interactive commands.

const (
	// User has not turned interactive mode on or off, default to off.
	InteractiveSoftOff InteractiveLevel = iota
	// User has explicitly turned interactive mode off.
	InteractiveHardOff
	// User only explicitly turned interactive mode on.
	InteractiveOnAll
)

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