You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The daemon timeout and interval flags are registered as strings, normalized and validated late in validateFlags, then re-parsed in buildAPIOptions/buildDaemonOptions. Normalization and validation are split across a per-flag table in validateFlags and each option builder, and durations are stored as string with an invariant (valid, positive duration) the type does not enforce. This shape is what allowed --timeout-mcp-shutdown to be validated but never applied until #284.
A custom pflag.Value duration type would normalize and validate once, at flag-parse time, and let the config carry time.Duration:
typedurationSecondsstruct{ d time.Duration }
func (v*durationSeconds) Set(sstring) error {
s=strings.TrimSpace(s)
if_, err:=time.ParseDuration(s); err!=nil {
if_, err2:=time.ParseDuration(s+"s"); err2==nil {
s+="s"// bare number -> seconds
}
}
d, err:=time.ParseDuration(s)
iferr!=nil {
returnfmt.Errorf("must be a duration such as 30s or 1m")
}
ifd<=0 {
returnfmt.Errorf("must be positive")
}
v.d=dreturnnil
}
func (v*durationSeconds) String() string { returnv.d.String() }
func (v*durationSeconds) Type() string { return"duration" }
Registered with Flags().Var(...), this would:
Normalize and validate once, when cobra parses the flag, before RunE — invalid input fails immediately with a per-flag error.
Store time.Duration in the config struct, so buildAPIOptions/buildDaemonOptions read the value directly with no re-parse and no duplicated error handling.
Stop validateFlags mutating config as a side effect.
Scope
Every timeout/interval flag registration (StringVar -> Var).
timeoutFlagConfig/intervalFlagConfig field types (string -> time.Duration).
Both option builders (drop the re-parse).
The config-file loaders and formatConfigInfo default rendering.
Tests that currently assert string values such as "15s".
Unifying with the config layer's config.Duration (JSON/TOML/YAML) type is the substantive design work — there should be one canonical duration representation across flags and config.
Whether validateFlags should accumulate errors with errors.Join rather than returning the first.
--help default rendering: with Var, the default shown comes from String(), so defaults must be seeded before registration.
pflag's built-in DurationVar cannot be reused because it rejects bare numbers. Follow-up from #284, which fixed the immediate bugs (bare-seconds normalization, positive validation, wiring --timeout-mcp-shutdown) and left this structural change as separate work.
The daemon timeout and interval flags are registered as strings, normalized and validated late in
validateFlags, then re-parsed inbuildAPIOptions/buildDaemonOptions. Normalization and validation are split across a per-flag table invalidateFlagsand each option builder, and durations are stored asstringwith an invariant (valid, positive duration) the type does not enforce. This shape is what allowed--timeout-mcp-shutdownto be validated but never applied until #284.A custom
pflag.Valueduration type would normalize and validate once, at flag-parse time, and let the config carrytime.Duration:Registered with
Flags().Var(...), this would:RunE— invalid input fails immediately with a per-flag error.time.Durationin the config struct, sobuildAPIOptions/buildDaemonOptionsread the value directly with no re-parse and no duplicated error handling.validateFlagsmutating config as a side effect.Scope
StringVar->Var).timeoutFlagConfig/intervalFlagConfigfield types (string->time.Duration).formatConfigInfodefault rendering."15s".config.Duration(JSON/TOML/YAML) type is the substantive design work — there should be one canonical duration representation across flags and config.Open questions to settle
0should ever be valid for any duration flag. fix(cmd): accept bare seconds, reject negatives, and wire --timeout-mcp-shutdown for daemon timeouts #284 rejects non-positive at the CLI; the configValidate()methods already reject non-positive.--interval-mcp-healthunit-required.validateFlagsshould accumulate errors witherrors.Joinrather than returning the first.--helpdefault rendering: withVar, the default shown comes fromString(), so defaults must be seeded before registration.pflag's built-inDurationVarcannot be reused because it rejects bare numbers. Follow-up from #284, which fixed the immediate bugs (bare-seconds normalization, positive validation, wiring--timeout-mcp-shutdown) and left this structural change as separate work.