@@ -5,17 +5,17 @@ import (
55 "log"
66 "os"
77 "path/filepath"
8- "strconv"
98 "time"
109
1110 "github.com/spf13/pflag"
1211
1312 "github.com/go-task/task/v3"
1413 "github.com/go-task/task/v3/errors"
1514 "github.com/go-task/task/v3/experiments"
16- "github.com/go-task/task/v3/internal/env"
1715 "github.com/go-task/task/v3/internal/sort"
1816 "github.com/go-task/task/v3/taskfile/ast"
17+ "github.com/go-task/task/v3/taskrc"
18+ taskrcast "github.com/go-task/task/v3/taskrc/ast"
1919)
2020
2121const usage = `Usage: task [flags...] [task...]
@@ -95,7 +95,9 @@ func init() {
9595
9696 // Parse the experiments
9797 dir = cmp .Or (dir , filepath .Dir (entrypoint ))
98- experiments .Parse (dir )
98+
99+ config , _ := taskrc .GetConfig (dir )
100+ experiments .ParseWithConfig (dir , config )
99101
100102 // Parse the rest of the flags
101103 log .SetFlags (0 )
@@ -104,10 +106,7 @@ func init() {
104106 log .Print (usage )
105107 pflag .PrintDefaults ()
106108 }
107- offline , err := strconv .ParseBool (cmp .Or (env .GetTaskEnv ("OFFLINE" ), "false" ))
108- if err != nil {
109- offline = false
110- }
109+
111110 pflag .BoolVar (& Version , "version" , false , "Show Task version." )
112111 pflag .BoolVarP (& Help , "help" , "h" , false , "Shows Task usage." )
113112 pflag .BoolVarP (& Init , "init" , "i" , false , "Creates a new Taskfile.yml in the current folder." )
@@ -118,9 +117,9 @@ func init() {
118117 pflag .StringVar (& TaskSort , "sort" , "" , "Changes the order of the tasks when listed. [default|alphanumeric|none]." )
119118 pflag .BoolVar (& Status , "status" , false , "Exits with non-zero exit code if any of the given tasks is not up-to-date." )
120119 pflag .BoolVar (& NoStatus , "no-status" , false , "Ignore status when listing tasks as JSON" )
121- pflag .BoolVar (& Insecure , "insecure" , false , "Forces Task to download Taskfiles over insecure connections." )
120+ pflag .BoolVar (& Insecure , "insecure" , getConfig ( config , config . Remote . Insecure , false ) , "Forces Task to download Taskfiles over insecure connections." )
122121 pflag .BoolVarP (& Watch , "watch" , "w" , false , "Enables watch of the given task." )
123- pflag .BoolVarP (& Verbose , "verbose" , "v" , false , "Enables verbose mode." )
122+ pflag .BoolVarP (& Verbose , "verbose" , "v" , getConfig ( config , config . Verbose , false ) , "Enables verbose mode." )
124123 pflag .BoolVarP (& Silent , "silent" , "s" , false , "Disables echoing." )
125124 pflag .BoolVarP (& AssumeYes , "yes" , "y" , false , "Assume \" yes\" as answer to all prompts." )
126125 pflag .BoolVarP (& Parallel , "parallel" , "p" , false , "Executes tasks provided on command line in parallel." )
@@ -134,7 +133,7 @@ func init() {
134133 pflag .StringVar (& Output .Group .End , "output-group-end" , "" , "Message template to print after a task's grouped output." )
135134 pflag .BoolVar (& Output .Group .ErrorOnly , "output-group-error-only" , false , "Swallow output from successful tasks." )
136135 pflag .BoolVarP (& Color , "color" , "c" , true , "Colored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable." )
137- pflag .IntVarP (& Concurrency , "concurrency" , "C" , 0 , "Limit number of tasks to run concurrently." )
136+ pflag .IntVarP (& Concurrency , "concurrency" , "C" , getConfig ( config , config . Concurrency , 0 ) , "Limit number of tasks to run concurrently." )
138137 pflag .DurationVarP (& Interval , "interval" , "I" , 0 , "Interval to watch for changes." )
139138 pflag .BoolVarP (& Global , "global" , "g" , false , "Runs global Taskfile, from $HOME/{T,t}askfile.{yml,yaml}." )
140139 pflag .BoolVar (& Experiments , "experiments" , false , "Lists all the available experiments and whether or not they are enabled." )
@@ -150,12 +149,11 @@ func init() {
150149 // Remote Taskfiles experiment will adds the "download" and "offline" flags
151150 if experiments .RemoteTaskfiles .Enabled () {
152151 pflag .BoolVar (& Download , "download" , false , "Downloads a cached version of a remote Taskfile." )
153- pflag .BoolVar (& Offline , "offline" , offline , "Forces Task to only use local or cached Taskfiles." )
154- pflag .DurationVar (& Timeout , "timeout" , time .Second * 10 , "Timeout for downloading remote Taskfiles." )
152+ pflag .BoolVar (& Offline , "offline" , getConfig ( config , config . Remote . Offline , false ) , "Forces Task to only use local or cached Taskfiles." )
153+ pflag .DurationVar (& Timeout , "timeout" , getConfig ( config , config . Remote . Timeout , time .Second * 10 ) , "Timeout for downloading remote Taskfiles." )
155154 pflag .BoolVar (& ClearCache , "clear-cache" , false , "Clear the remote cache." )
156- pflag .DurationVar (& CacheExpiryDuration , "expiry" , 0 , "Expiry duration for cached remote Taskfiles." )
155+ pflag .DurationVar (& CacheExpiryDuration , "expiry" , getConfig ( config , config . Remote . Timeout , 0 ) , "Expiry duration for cached remote Taskfiles." )
157156 }
158-
159157 pflag .Parse ()
160158}
161159
@@ -251,3 +249,15 @@ func (o *flagsOption) ApplyToExecutor(e *task.Executor) {
251249 task .WithVersionCheck (true ),
252250 )
253251}
252+
253+ // getConfig extracts a config value directly from a pointer field with a fallback default
254+ func getConfig [T any ](config * taskrcast.TaskRC , field * T , fallback T ) T {
255+ if config == nil {
256+ return fallback
257+ }
258+
259+ if field != nil {
260+ return * field
261+ }
262+ return fallback
263+ }
0 commit comments