Skip to content

fix: allow empty typed slice flag values#485

Closed
happysnaker wants to merge 1 commit into
spf13:masterfrom
happysnaker:fix-empty-typed-slice-values
Closed

fix: allow empty typed slice flag values#485
happysnaker wants to merge 1 commit into
spf13:masterfrom
happysnaker:fix-empty-typed-slice-values

Conversation

@happysnaker

Copy link
Copy Markdown

Summary

  • treat explicit empty values for typed comma-separated slice flags as empty slices instead of a single empty-string element
  • keep the behavior aligned across IntSlice, Int32Slice, Int64Slice, UintSlice, Float32Slice, Float64Slice, and DurationSlice
  • add regression coverage showing --flag= now produces a non-nil empty slice while leaving default values unchanged when the flag is omitted

Context

StringSlice already treats --flag= as an empty slice, but the typed slice implementations still fed the empty string through strings.Split, which turns it into []string{""} and then fails during numeric / duration parsing.

This change uses the same empty-input interpretation consistently for the typed slice variants, matching the expectation discussed in #222.

Notes

Closes #222

@happysnaker

Copy link
Copy Markdown
Author

Maintainer context for review:

  • this intentionally matches the collaborator guidance in Can't pass empty int slices #222: an explicit --flag= now becomes a non-nil empty slice, while omitting the flag still preserves the existing default value
  • scope is limited to the typed comma-separated slice flags that still errored on the empty-string split path (IntSlice, Int32Slice, Int64Slice, UintSlice, Float32Slice, Float64Slice, DurationSlice)
  • StringSlice already had this empty-value behavior, so the change is mainly about making the typed slice variants consistent instead of introducing a brand-new flag syntax

@tomasaschan

Copy link
Copy Markdown
Collaborator

Same as #486.

@tomasaschan tomasaschan closed this Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't pass empty int slices

2 participants