go mod vendor
+ move k8s.io/apimachinery fork from go.work to go.mod (and include it in vendor)
This commit is contained in:
80
vendor/github.com/magefile/mage/mg/color.go
generated
vendored
Normal file
80
vendor/github.com/magefile/mage/mg/color.go
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
package mg
|
||||
|
||||
// Color is ANSI color type
|
||||
type Color int
|
||||
|
||||
// If you add/change/remove any items in this constant,
|
||||
// you will need to run "stringer -type=Color" in this directory again.
|
||||
// NOTE: Please keep the list in an alphabetical order.
|
||||
const (
|
||||
Black Color = iota
|
||||
Red
|
||||
Green
|
||||
Yellow
|
||||
Blue
|
||||
Magenta
|
||||
Cyan
|
||||
White
|
||||
BrightBlack
|
||||
BrightRed
|
||||
BrightGreen
|
||||
BrightYellow
|
||||
BrightBlue
|
||||
BrightMagenta
|
||||
BrightCyan
|
||||
BrightWhite
|
||||
)
|
||||
|
||||
// AnsiColor are ANSI color codes for supported terminal colors.
|
||||
var ansiColor = map[Color]string{
|
||||
Black: "\u001b[30m",
|
||||
Red: "\u001b[31m",
|
||||
Green: "\u001b[32m",
|
||||
Yellow: "\u001b[33m",
|
||||
Blue: "\u001b[34m",
|
||||
Magenta: "\u001b[35m",
|
||||
Cyan: "\u001b[36m",
|
||||
White: "\u001b[37m",
|
||||
BrightBlack: "\u001b[30;1m",
|
||||
BrightRed: "\u001b[31;1m",
|
||||
BrightGreen: "\u001b[32;1m",
|
||||
BrightYellow: "\u001b[33;1m",
|
||||
BrightBlue: "\u001b[34;1m",
|
||||
BrightMagenta: "\u001b[35;1m",
|
||||
BrightCyan: "\u001b[36;1m",
|
||||
BrightWhite: "\u001b[37;1m",
|
||||
}
|
||||
|
||||
// AnsiColorReset is an ANSI color code to reset the terminal color.
|
||||
const AnsiColorReset = "\033[0m"
|
||||
|
||||
// DefaultTargetAnsiColor is a default ANSI color for colorizing targets.
|
||||
// It is set to Cyan as an arbitrary color, because it has a neutral meaning
|
||||
var DefaultTargetAnsiColor = ansiColor[Cyan]
|
||||
|
||||
func toLowerCase(s string) string {
|
||||
// this is a naive implementation
|
||||
// borrowed from https://golang.org/src/strings/strings.go
|
||||
// and only considers alphabetical characters [a-zA-Z]
|
||||
// so that we don't depend on the "strings" package
|
||||
buf := make([]byte, len(s))
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if 'A' <= c && c <= 'Z' {
|
||||
c += 'a' - 'A'
|
||||
}
|
||||
buf[i] = c
|
||||
}
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
func getAnsiColor(color string) (string, bool) {
|
||||
colorLower := toLowerCase(color)
|
||||
for k, v := range ansiColor {
|
||||
colorConstLower := toLowerCase(k.String())
|
||||
if colorConstLower == colorLower {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
38
vendor/github.com/magefile/mage/mg/color_string.go
generated
vendored
Normal file
38
vendor/github.com/magefile/mage/mg/color_string.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Code generated by "stringer -type=Color"; DO NOT EDIT.
|
||||
|
||||
package mg
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[Black-0]
|
||||
_ = x[Red-1]
|
||||
_ = x[Green-2]
|
||||
_ = x[Yellow-3]
|
||||
_ = x[Blue-4]
|
||||
_ = x[Magenta-5]
|
||||
_ = x[Cyan-6]
|
||||
_ = x[White-7]
|
||||
_ = x[BrightBlack-8]
|
||||
_ = x[BrightRed-9]
|
||||
_ = x[BrightGreen-10]
|
||||
_ = x[BrightYellow-11]
|
||||
_ = x[BrightBlue-12]
|
||||
_ = x[BrightMagenta-13]
|
||||
_ = x[BrightCyan-14]
|
||||
_ = x[BrightWhite-15]
|
||||
}
|
||||
|
||||
const _Color_name = "BlackRedGreenYellowBlueMagentaCyanWhiteBrightBlackBrightRedBrightGreenBrightYellowBrightBlueBrightMagentaBrightCyanBrightWhite"
|
||||
|
||||
var _Color_index = [...]uint8{0, 5, 8, 13, 19, 23, 30, 34, 39, 50, 59, 70, 82, 92, 105, 115, 126}
|
||||
|
||||
func (i Color) String() string {
|
||||
if i < 0 || i >= Color(len(_Color_index)-1) {
|
||||
return "Color(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Color_name[_Color_index[i]:_Color_index[i+1]]
|
||||
}
|
211
vendor/github.com/magefile/mage/mg/deps.go
generated
vendored
Normal file
211
vendor/github.com/magefile/mage/mg/deps.go
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
package mg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var logger = log.New(os.Stderr, "", 0)
|
||||
|
||||
type onceMap struct {
|
||||
mu *sync.Mutex
|
||||
m map[onceKey]*onceFun
|
||||
}
|
||||
|
||||
type onceKey struct {
|
||||
Name string
|
||||
ID string
|
||||
}
|
||||
|
||||
func (o *onceMap) LoadOrStore(f Fn) *onceFun {
|
||||
defer o.mu.Unlock()
|
||||
o.mu.Lock()
|
||||
|
||||
key := onceKey{
|
||||
Name: f.Name(),
|
||||
ID: f.ID(),
|
||||
}
|
||||
existing, ok := o.m[key]
|
||||
if ok {
|
||||
return existing
|
||||
}
|
||||
one := &onceFun{
|
||||
once: &sync.Once{},
|
||||
fn: f,
|
||||
displayName: displayName(f.Name()),
|
||||
}
|
||||
o.m[key] = one
|
||||
return one
|
||||
}
|
||||
|
||||
var onces = &onceMap{
|
||||
mu: &sync.Mutex{},
|
||||
m: map[onceKey]*onceFun{},
|
||||
}
|
||||
|
||||
// SerialDeps is like Deps except it runs each dependency serially, instead of
|
||||
// in parallel. This can be useful for resource intensive dependencies that
|
||||
// shouldn't be run at the same time.
|
||||
func SerialDeps(fns ...interface{}) {
|
||||
funcs := checkFns(fns)
|
||||
ctx := context.Background()
|
||||
for i := range fns {
|
||||
runDeps(ctx, funcs[i:i+1])
|
||||
}
|
||||
}
|
||||
|
||||
// SerialCtxDeps is like CtxDeps except it runs each dependency serially,
|
||||
// instead of in parallel. This can be useful for resource intensive
|
||||
// dependencies that shouldn't be run at the same time.
|
||||
func SerialCtxDeps(ctx context.Context, fns ...interface{}) {
|
||||
funcs := checkFns(fns)
|
||||
for i := range fns {
|
||||
runDeps(ctx, funcs[i:i+1])
|
||||
}
|
||||
}
|
||||
|
||||
// CtxDeps runs the given functions as dependencies of the calling function.
|
||||
// Dependencies must only be of type:
|
||||
// func()
|
||||
// func() error
|
||||
// func(context.Context)
|
||||
// func(context.Context) error
|
||||
// Or a similar method on a mg.Namespace type.
|
||||
// Or an mg.Fn interface.
|
||||
//
|
||||
// The function calling Deps is guaranteed that all dependent functions will be
|
||||
// run exactly once when Deps returns. Dependent functions may in turn declare
|
||||
// their own dependencies using Deps. Each dependency is run in their own
|
||||
// goroutines. Each function is given the context provided if the function
|
||||
// prototype allows for it.
|
||||
func CtxDeps(ctx context.Context, fns ...interface{}) {
|
||||
funcs := checkFns(fns)
|
||||
runDeps(ctx, funcs)
|
||||
}
|
||||
|
||||
// runDeps assumes you've already called checkFns.
|
||||
func runDeps(ctx context.Context, fns []Fn) {
|
||||
mu := &sync.Mutex{}
|
||||
var errs []string
|
||||
var exit int
|
||||
wg := &sync.WaitGroup{}
|
||||
for _, f := range fns {
|
||||
fn := onces.LoadOrStore(f)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer func() {
|
||||
if v := recover(); v != nil {
|
||||
mu.Lock()
|
||||
if err, ok := v.(error); ok {
|
||||
exit = changeExit(exit, ExitStatus(err))
|
||||
} else {
|
||||
exit = changeExit(exit, 1)
|
||||
}
|
||||
errs = append(errs, fmt.Sprint(v))
|
||||
mu.Unlock()
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
if err := fn.run(ctx); err != nil {
|
||||
mu.Lock()
|
||||
errs = append(errs, fmt.Sprint(err))
|
||||
exit = changeExit(exit, ExitStatus(err))
|
||||
mu.Unlock()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
if len(errs) > 0 {
|
||||
panic(Fatal(exit, strings.Join(errs, "\n")))
|
||||
}
|
||||
}
|
||||
|
||||
func checkFns(fns []interface{}) []Fn {
|
||||
funcs := make([]Fn, len(fns))
|
||||
for i, f := range fns {
|
||||
if fn, ok := f.(Fn); ok {
|
||||
funcs[i] = fn
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if the target provided is a not function so we can give a clear warning
|
||||
t := reflect.TypeOf(f)
|
||||
if t == nil || t.Kind() != reflect.Func {
|
||||
panic(fmt.Errorf("non-function used as a target dependency: %T. The mg.Deps, mg.SerialDeps and mg.CtxDeps functions accept function names, such as mg.Deps(TargetA, TargetB)", f))
|
||||
}
|
||||
|
||||
funcs[i] = F(f)
|
||||
}
|
||||
return funcs
|
||||
}
|
||||
|
||||
// Deps runs the given functions in parallel, exactly once. Dependencies must
|
||||
// only be of type:
|
||||
// func()
|
||||
// func() error
|
||||
// func(context.Context)
|
||||
// func(context.Context) error
|
||||
// Or a similar method on a mg.Namespace type.
|
||||
// Or an mg.Fn interface.
|
||||
//
|
||||
// This is a way to build up a tree of dependencies with each dependency
|
||||
// defining its own dependencies. Functions must have the same signature as a
|
||||
// Mage target, i.e. optional context argument, optional error return.
|
||||
func Deps(fns ...interface{}) {
|
||||
CtxDeps(context.Background(), fns...)
|
||||
}
|
||||
|
||||
func changeExit(old, new int) int {
|
||||
if new == 0 {
|
||||
return old
|
||||
}
|
||||
if old == 0 {
|
||||
return new
|
||||
}
|
||||
if old == new {
|
||||
return old
|
||||
}
|
||||
// both different and both non-zero, just set
|
||||
// exit to 1. Nothing more we can do.
|
||||
return 1
|
||||
}
|
||||
|
||||
// funcName returns the unique name for the function
|
||||
func funcName(i interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
||||
}
|
||||
|
||||
func displayName(name string) string {
|
||||
splitByPackage := strings.Split(name, ".")
|
||||
if len(splitByPackage) == 2 && splitByPackage[0] == "main" {
|
||||
return splitByPackage[len(splitByPackage)-1]
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
type onceFun struct {
|
||||
once *sync.Once
|
||||
fn Fn
|
||||
err error
|
||||
|
||||
displayName string
|
||||
}
|
||||
|
||||
// run will run the function exactly once and capture the error output. Further runs simply return
|
||||
// the same error output.
|
||||
func (o *onceFun) run(ctx context.Context) error {
|
||||
o.once.Do(func() {
|
||||
if Verbose() {
|
||||
logger.Println("Running dependency:", displayName(o.fn.Name()))
|
||||
}
|
||||
o.err = o.fn.Run(ctx)
|
||||
})
|
||||
return o.err
|
||||
}
|
51
vendor/github.com/magefile/mage/mg/errors.go
generated
vendored
Normal file
51
vendor/github.com/magefile/mage/mg/errors.go
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
package mg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type fatalErr struct {
|
||||
code int
|
||||
error
|
||||
}
|
||||
|
||||
func (f fatalErr) ExitStatus() int {
|
||||
return f.code
|
||||
}
|
||||
|
||||
type exitStatus interface {
|
||||
ExitStatus() int
|
||||
}
|
||||
|
||||
// Fatal returns an error that will cause mage to print out the
|
||||
// given args and exit with the given exit code.
|
||||
func Fatal(code int, args ...interface{}) error {
|
||||
return fatalErr{
|
||||
code: code,
|
||||
error: errors.New(fmt.Sprint(args...)),
|
||||
}
|
||||
}
|
||||
|
||||
// Fatalf returns an error that will cause mage to print out the
|
||||
// given message and exit with the given exit code.
|
||||
func Fatalf(code int, format string, args ...interface{}) error {
|
||||
return fatalErr{
|
||||
code: code,
|
||||
error: fmt.Errorf(format, args...),
|
||||
}
|
||||
}
|
||||
|
||||
// ExitStatus queries the error for an exit status. If the error is nil, it
|
||||
// returns 0. If the error does not implement ExitStatus() int, it returns 1.
|
||||
// Otherwise it retiurns the value from ExitStatus().
|
||||
func ExitStatus(err error) int {
|
||||
if err == nil {
|
||||
return 0
|
||||
}
|
||||
exit, ok := err.(exitStatus)
|
||||
if !ok {
|
||||
return 1
|
||||
}
|
||||
return exit.ExitStatus()
|
||||
}
|
192
vendor/github.com/magefile/mage/mg/fn.go
generated
vendored
Normal file
192
vendor/github.com/magefile/mage/mg/fn.go
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
package mg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Fn represents a function that can be run with mg.Deps. Package, Name, and ID must combine to
|
||||
// uniquely identify a function, while ensuring the "same" function has identical values. These are
|
||||
// used as a map key to find and run (or not run) the function.
|
||||
type Fn interface {
|
||||
// Name should return the fully qualified name of the function. Usually
|
||||
// it's best to use runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name().
|
||||
Name() string
|
||||
|
||||
// ID should be an additional uniqueness qualifier in case the name is insufficiently unique.
|
||||
// This can be the case for functions that take arguments (mg.F json-encodes an array of the
|
||||
// args).
|
||||
ID() string
|
||||
|
||||
// Run should run the function.
|
||||
Run(ctx context.Context) error
|
||||
}
|
||||
|
||||
// F takes a function that is compatible as a mage target, and any args that need to be passed to
|
||||
// it, and wraps it in an mg.Fn that mg.Deps can run. Args must be passed in the same order as they
|
||||
// are declared by the function. Note that you do not need to and should not pass a context.Context
|
||||
// to F, even if the target takes a context. Compatible args are int, bool, string, and
|
||||
// time.Duration.
|
||||
func F(target interface{}, args ...interface{}) Fn {
|
||||
hasContext, isNamespace, err := checkF(target, args)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
id, err := json.Marshal(args)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("can't convert args into a mage-compatible id for mg.Deps: %s", err))
|
||||
}
|
||||
return fn{
|
||||
name: funcName(target),
|
||||
id: string(id),
|
||||
f: func(ctx context.Context) error {
|
||||
v := reflect.ValueOf(target)
|
||||
count := len(args)
|
||||
if hasContext {
|
||||
count++
|
||||
}
|
||||
if isNamespace {
|
||||
count++
|
||||
}
|
||||
vargs := make([]reflect.Value, count)
|
||||
x := 0
|
||||
if isNamespace {
|
||||
vargs[0] = reflect.ValueOf(struct{}{})
|
||||
x++
|
||||
}
|
||||
if hasContext {
|
||||
vargs[x] = reflect.ValueOf(ctx)
|
||||
x++
|
||||
}
|
||||
for y := range args {
|
||||
vargs[x+y] = reflect.ValueOf(args[y])
|
||||
}
|
||||
ret := v.Call(vargs)
|
||||
if len(ret) > 0 {
|
||||
// we only allow functions with a single error return, so this should be safe.
|
||||
if ret[0].IsNil() {
|
||||
return nil
|
||||
}
|
||||
return ret[0].Interface().(error)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fn struct {
|
||||
name string
|
||||
id string
|
||||
f func(ctx context.Context) error
|
||||
}
|
||||
|
||||
// Name returns the fully qualified name of the function.
|
||||
func (f fn) Name() string {
|
||||
return f.name
|
||||
}
|
||||
|
||||
// ID returns a hash of the argument values passed in
|
||||
func (f fn) ID() string {
|
||||
return f.id
|
||||
}
|
||||
|
||||
// Run runs the function.
|
||||
func (f fn) Run(ctx context.Context) error {
|
||||
return f.f(ctx)
|
||||
}
|
||||
|
||||
func checkF(target interface{}, args []interface{}) (hasContext, isNamespace bool, _ error) {
|
||||
t := reflect.TypeOf(target)
|
||||
if t == nil || t.Kind() != reflect.Func {
|
||||
return false, false, fmt.Errorf("non-function passed to mg.F: %T. The mg.F function accepts function names, such as mg.F(TargetA, \"arg1\", \"arg2\")", target)
|
||||
}
|
||||
|
||||
if t.NumOut() > 1 {
|
||||
return false, false, fmt.Errorf("target has too many return values, must be zero or just an error: %T", target)
|
||||
}
|
||||
if t.NumOut() == 1 && t.Out(0) != errType {
|
||||
return false, false, fmt.Errorf("target's return value is not an error")
|
||||
}
|
||||
|
||||
// more inputs than slots is an error if not variadic
|
||||
if len(args) > t.NumIn() && !t.IsVariadic() {
|
||||
return false, false, fmt.Errorf("too many arguments for target, got %d for %T", len(args), target)
|
||||
}
|
||||
|
||||
if t.NumIn() == 0 {
|
||||
return false, false, nil
|
||||
}
|
||||
|
||||
x := 0
|
||||
inputs := t.NumIn()
|
||||
|
||||
if t.In(0).AssignableTo(emptyType) {
|
||||
// nameSpace func
|
||||
isNamespace = true
|
||||
x++
|
||||
// callers must leave off the namespace value
|
||||
inputs--
|
||||
}
|
||||
if t.NumIn() > x && t.In(x) == ctxType {
|
||||
// callers must leave off the context
|
||||
inputs--
|
||||
|
||||
// let the upper function know it should pass us a context.
|
||||
hasContext = true
|
||||
|
||||
// skip checking the first argument in the below loop if it's a context, since first arg is
|
||||
// special.
|
||||
x++
|
||||
}
|
||||
|
||||
if t.IsVariadic() {
|
||||
if len(args) < inputs-1 {
|
||||
return false, false, fmt.Errorf("too few arguments for target, got %d for %T", len(args), target)
|
||||
|
||||
}
|
||||
} else if len(args) != inputs {
|
||||
return false, false, fmt.Errorf("wrong number of arguments for target, got %d for %T", len(args), target)
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
argT := t.In(x)
|
||||
if t.IsVariadic() && x == t.NumIn()-1 {
|
||||
// For the variadic argument, use the slice element type.
|
||||
argT = argT.Elem()
|
||||
}
|
||||
if !argTypes[argT] {
|
||||
return false, false, fmt.Errorf("argument %d (%s), is not a supported argument type", x, argT)
|
||||
}
|
||||
passedT := reflect.TypeOf(arg)
|
||||
if argT != passedT {
|
||||
return false, false, fmt.Errorf("argument %d expected to be %s, but is %s", x, argT, passedT)
|
||||
}
|
||||
if x < t.NumIn()-1 {
|
||||
x++
|
||||
}
|
||||
}
|
||||
return hasContext, isNamespace, nil
|
||||
}
|
||||
|
||||
// Here we define the types that are supported as arguments/returns
|
||||
var (
|
||||
ctxType = reflect.TypeOf(func(context.Context) {}).In(0)
|
||||
errType = reflect.TypeOf(func() error { return nil }).Out(0)
|
||||
emptyType = reflect.TypeOf(struct{}{})
|
||||
|
||||
intType = reflect.TypeOf(int(0))
|
||||
stringType = reflect.TypeOf(string(""))
|
||||
boolType = reflect.TypeOf(bool(false))
|
||||
durType = reflect.TypeOf(time.Second)
|
||||
|
||||
// don't put ctx in here, this is for non-context types
|
||||
argTypes = map[reflect.Type]bool{
|
||||
intType: true,
|
||||
boolType: true,
|
||||
stringType: true,
|
||||
durType: true,
|
||||
}
|
||||
)
|
136
vendor/github.com/magefile/mage/mg/runtime.go
generated
vendored
Normal file
136
vendor/github.com/magefile/mage/mg/runtime.go
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
package mg
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// CacheEnv is the environment variable that users may set to change the
|
||||
// location where mage stores its compiled binaries.
|
||||
const CacheEnv = "MAGEFILE_CACHE"
|
||||
|
||||
// VerboseEnv is the environment variable that indicates the user requested
|
||||
// verbose mode when running a magefile.
|
||||
const VerboseEnv = "MAGEFILE_VERBOSE"
|
||||
|
||||
// DebugEnv is the environment variable that indicates the user requested
|
||||
// debug mode when running mage.
|
||||
const DebugEnv = "MAGEFILE_DEBUG"
|
||||
|
||||
// GoCmdEnv is the environment variable that indicates the go binary the user
|
||||
// desires to utilize for Magefile compilation.
|
||||
const GoCmdEnv = "MAGEFILE_GOCMD"
|
||||
|
||||
// IgnoreDefaultEnv is the environment variable that indicates the user requested
|
||||
// to ignore the default target specified in the magefile.
|
||||
const IgnoreDefaultEnv = "MAGEFILE_IGNOREDEFAULT"
|
||||
|
||||
// HashFastEnv is the environment variable that indicates the user requested to
|
||||
// use a quick hash of magefiles to determine whether or not the magefile binary
|
||||
// needs to be rebuilt. This results in faster runtimes, but means that mage
|
||||
// will fail to rebuild if a dependency has changed. To force a rebuild, run
|
||||
// mage with the -f flag.
|
||||
const HashFastEnv = "MAGEFILE_HASHFAST"
|
||||
|
||||
// EnableColorEnv is the environment variable that indicates the user is using
|
||||
// a terminal which supports a color output. The default is false for backwards
|
||||
// compatibility. When the value is true and the detected terminal does support colors
|
||||
// then the list of mage targets will be displayed in ANSI color. When the value
|
||||
// is true but the detected terminal does not support colors, then the list of
|
||||
// mage targets will be displayed in the default colors (e.g. black and white).
|
||||
const EnableColorEnv = "MAGEFILE_ENABLE_COLOR"
|
||||
|
||||
// TargetColorEnv is the environment variable that indicates which ANSI color
|
||||
// should be used to colorize mage targets. This is only applicable when
|
||||
// the MAGEFILE_ENABLE_COLOR environment variable is true.
|
||||
// The supported ANSI color names are any of these:
|
||||
// - Black
|
||||
// - Red
|
||||
// - Green
|
||||
// - Yellow
|
||||
// - Blue
|
||||
// - Magenta
|
||||
// - Cyan
|
||||
// - White
|
||||
// - BrightBlack
|
||||
// - BrightRed
|
||||
// - BrightGreen
|
||||
// - BrightYellow
|
||||
// - BrightBlue
|
||||
// - BrightMagenta
|
||||
// - BrightCyan
|
||||
// - BrightWhite
|
||||
const TargetColorEnv = "MAGEFILE_TARGET_COLOR"
|
||||
|
||||
// Verbose reports whether a magefile was run with the verbose flag.
|
||||
func Verbose() bool {
|
||||
b, _ := strconv.ParseBool(os.Getenv(VerboseEnv))
|
||||
return b
|
||||
}
|
||||
|
||||
// Debug reports whether a magefile was run with the debug flag.
|
||||
func Debug() bool {
|
||||
b, _ := strconv.ParseBool(os.Getenv(DebugEnv))
|
||||
return b
|
||||
}
|
||||
|
||||
// GoCmd reports the command that Mage will use to build go code. By default mage runs
|
||||
// the "go" binary in the PATH.
|
||||
func GoCmd() string {
|
||||
if cmd := os.Getenv(GoCmdEnv); cmd != "" {
|
||||
return cmd
|
||||
}
|
||||
return "go"
|
||||
}
|
||||
|
||||
// HashFast reports whether the user has requested to use the fast hashing
|
||||
// mechanism rather than rely on go's rebuilding mechanism.
|
||||
func HashFast() bool {
|
||||
b, _ := strconv.ParseBool(os.Getenv(HashFastEnv))
|
||||
return b
|
||||
}
|
||||
|
||||
// IgnoreDefault reports whether the user has requested to ignore the default target
|
||||
// in the magefile.
|
||||
func IgnoreDefault() bool {
|
||||
b, _ := strconv.ParseBool(os.Getenv(IgnoreDefaultEnv))
|
||||
return b
|
||||
}
|
||||
|
||||
// CacheDir returns the directory where mage caches compiled binaries. It
|
||||
// defaults to $HOME/.magefile, but may be overridden by the MAGEFILE_CACHE
|
||||
// environment variable.
|
||||
func CacheDir() string {
|
||||
d := os.Getenv(CacheEnv)
|
||||
if d != "" {
|
||||
return d
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
return filepath.Join(os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"), "magefile")
|
||||
default:
|
||||
return filepath.Join(os.Getenv("HOME"), ".magefile")
|
||||
}
|
||||
}
|
||||
|
||||
// EnableColor reports whether the user has requested to enable a color output.
|
||||
func EnableColor() bool {
|
||||
b, _ := strconv.ParseBool(os.Getenv(EnableColorEnv))
|
||||
return b
|
||||
}
|
||||
|
||||
// TargetColor returns the configured ANSI color name a color output.
|
||||
func TargetColor() string {
|
||||
s, exists := os.LookupEnv(TargetColorEnv)
|
||||
if exists {
|
||||
if c, ok := getAnsiColor(s); ok {
|
||||
return c
|
||||
}
|
||||
}
|
||||
return DefaultTargetAnsiColor
|
||||
}
|
||||
|
||||
// Namespace allows for the grouping of similar commands
|
||||
type Namespace struct{}
|
Reference in New Issue
Block a user