MCPcopy Create free account
hub / github.com/coder/envbox / DurationVarP

Function DurationVarP

cli/cliflag/cliflag.go:156–170  ·  view source on GitHub ↗

DurationVarP sets a time.Duration flag on the given flag set.

(flagset *pflag.FlagSet, ptr *time.Duration, name string, shorthand string, env string, def time.Duration, usage string)

Source from the content-addressed store, hash-verified

154
155// DurationVarP sets a time.Duration flag on the given flag set.
156func DurationVarP(flagset *pflag.FlagSet, ptr *time.Duration, name string, shorthand string, env string, def time.Duration, usage string) {
157 val, ok := os.LookupEnv(env)
158 if !ok || val == "" {
159 flagset.DurationVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
160 return
161 }
162
163 valb, err := time.ParseDuration(val)
164 if err != nil {
165 flagset.DurationVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
166 return
167 }
168
169 flagset.DurationVarP(ptr, name, shorthand, valb, fmtUsage(usage, env))
170}
171
172func fmtUsage(u string, env string) string {
173 if env != "" {

Callers 1

TestCliflagFunction · 0.92

Calls 1

fmtUsageFunction · 0.85

Tested by 1

TestCliflagFunction · 0.74