MCPcopy Index your code
hub / github.com/go-task/task / getEnvAs

Function getEnvAs

internal/flags/flags.go:333–358  ·  view source on GitHub ↗

getEnvAs parses a TASK_ prefixed env var as type T

(envKey string)

Source from the content-addressed store, hash-verified

331
332// getEnvAs parses a TASK_ prefixed env var as type T
333func getEnvAs[T any](envKey string) (T, bool) {
334 var zero T
335 switch any(zero).(type) {
336 case bool:
337 if val, ok := env.GetTaskEnvBool(envKey); ok {
338 return any(val).(T), true
339 }
340 case int:
341 if val, ok := env.GetTaskEnvInt(envKey); ok {
342 return any(val).(T), true
343 }
344 case time.Duration:
345 if val, ok := env.GetTaskEnvDuration(envKey); ok {
346 return any(val).(T), true
347 }
348 case string:
349 if val, ok := env.GetTaskEnvString(envKey); ok {
350 return any(val).(T), true
351 }
352 case []string:
353 if val, ok := env.GetTaskEnvStringSlice(envKey); ok {
354 return any(val).(T), true
355 }
356 }
357 return zero, false
358}

Callers

nothing calls this directly

Calls 5

GetTaskEnvBoolFunction · 0.92
GetTaskEnvIntFunction · 0.92
GetTaskEnvDurationFunction · 0.92
GetTaskEnvStringFunction · 0.92
GetTaskEnvStringSliceFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…