1
0
mirror of https://github.com/go-task/task.git synced 2024-12-16 10:59:23 +02:00
task/internal/experiments/experiments.go
Pete Davison 22ce67c5e5
feat: remote taskfiles (HTTP) (#1152)
* feat: remote taskfiles over http

* feat: allow insecure connections when --insecure flag is provided

* feat: better error handling for fetch errors

* fix: ensure cache directory always exists

* fix: setup logger before everything else

* feat: put remote taskfiles behind an experiment

* feat: --download and --offline flags for remote taskfiles

* feat: node.Read accepts a context

* feat: experiment docs

* chore: changelog

* chore: remove unused optional param from Node interface

* chore: tidy up and generalise NewNode function

* fix: use sha256 in remote checksum

* feat: --download by itself will not run a task

* feat: custom error if remote taskfiles experiment is not enabled

* refactor: BaseNode functional options and simplified FileNode

* fix: use hex encoding for checksum instead of b64
2023-09-12 22:42:54 +01:00

56 lines
1.1 KiB
Go

package experiments
import (
"fmt"
"io"
"os"
"strings"
"text/tabwriter"
"github.com/joho/godotenv"
"github.com/go-task/task/v3/internal/logger"
)
const envPrefix = "TASK_X_"
// A list of experiments.
var (
GentleForce bool
RemoteTaskfiles bool
)
func init() {
readDotEnv()
GentleForce = parseEnv("GENTLE_FORCE")
RemoteTaskfiles = parseEnv("REMOTE_TASKFILES")
}
func parseEnv(xName string) bool {
envName := fmt.Sprintf("%s%s", envPrefix, xName)
return os.Getenv(envName) == "1"
}
func readDotEnv() {
env, _ := godotenv.Read()
// If the env var is an experiment, set it.
for key, value := range env {
if strings.HasPrefix(key, envPrefix) {
os.Setenv(key, value)
}
}
}
func printExperiment(w io.Writer, l *logger.Logger, name string, value bool) {
l.FOutf(w, logger.Yellow, "* ")
l.FOutf(w, logger.Green, name)
l.FOutf(w, logger.Default, ": \t%t\n", value)
}
func List(l *logger.Logger) error {
w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, ' ', 0)
printExperiment(w, l, "GENTLE_FORCE", GentleForce)
printExperiment(w, l, "REMOTE_TASKFILES", RemoteTaskfiles)
return w.Flush()
}