From 46f7bba90d5aaa89a800ba3f06f75a983c4c10dd Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Fri, 30 Jun 2023 02:29:28 +0100 Subject: [PATCH] feat: experiments flag (#1242) --- CHANGELOG.md | 2 ++ cmd/task/task.go | 12 ++++++++++++ internal/experiments/experiments.go | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b78dd4f..ce9fd99e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ @sounisi5011). - Added the [gentle force experiment](https://taskfile.dev/experiments) as a draft (#1200, #1216 by @pd93). +- Added an `--experiments` flag to allow you to see which experiments are + enabled (#1242 by @pd93). - Added ability to specify which variables are required in a task (#1203, #1204 by @benc-uk). diff --git a/cmd/task/task.go b/cmd/task/task.go index b8a9bdf2..7642533f 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -70,6 +70,7 @@ var flags struct { color bool interval time.Duration global bool + experiments bool } func main() { @@ -129,6 +130,7 @@ func run() error { pflag.IntVarP(&flags.concurrency, "concurrency", "C", 0, "Limit number tasks to run concurrently.") pflag.DurationVarP(&flags.interval, "interval", "I", 0, "Interval to watch for changes.") pflag.BoolVarP(&flags.global, "global", "g", false, "Runs global Taskfile, from $HOME/{T,t}askfile.{yml,yaml}.") + pflag.BoolVar(&flags.experiments, "experiments", false, "Lists all the available experiments and whether or not they are enabled.") // Gentle force experiment will override the force flag and add a new force-all flag if experiments.GentleForce { @@ -150,6 +152,16 @@ func run() error { return nil } + if flags.experiments { + l := &logger.Logger{ + Stdout: os.Stdout, + Stderr: os.Stderr, + Verbose: flags.verbose, + Color: flags.color, + } + return experiments.List(l) + } + if flags.init { wd, err := os.Getwd() if err != nil { diff --git a/internal/experiments/experiments.go b/internal/experiments/experiments.go index df0e50e2..b8525936 100644 --- a/internal/experiments/experiments.go +++ b/internal/experiments/experiments.go @@ -5,8 +5,11 @@ import ( "fmt" "os" "strings" + "text/tabwriter" "github.com/joho/godotenv" + + "github.com/go-task/task/v3/internal/logger" ) const envPrefix = "TASK_X_" @@ -41,3 +44,11 @@ func readDotEnv() error { } return nil } + +func List(l *logger.Logger) error { + w := tabwriter.NewWriter(os.Stdout, 0, 8, 6, ' ', 0) + l.FOutf(w, logger.Yellow, "* ") + l.FOutf(w, logger.Green, "GENTLE_FORCE") + l.FOutf(w, logger.Default, ": \t%t\n", GentleForce) + return w.Flush() +}