diff --git a/internal/cmd/flag.go b/internal/cmd/flag.go index bf046b24..10cc1321 100644 --- a/internal/cmd/flag.go +++ b/internal/cmd/flag.go @@ -17,22 +17,15 @@ var _ flag.Value = (*uint32Value)(nil) // Set implements the [flag.Value] interface for *uint32Value. func (i *uint32Value) Set(s string) (err error) { - v, err := strconv.ParseInt(s, 0, 32) - if err != nil { - // Don't wrap the error, because it's informative enough as is. - return err - } else if v < 0 { - return fmt.Errorf("negative value: %v", v) - } - + v, err := strconv.ParseUint(s, 0, 32) *i = uint32Value(v) - return nil + return err } // String implements the [flag.Value] interface for *uint32Value. func (i *uint32Value) String() (out string) { - return strconv.Itoa(int(*i)) + return strconv.FormatUint(uint64(*i), 10) } // float32Value is an float32 that can be defined as a flag for [flag.FlagSet]. @@ -95,6 +88,10 @@ func (i *intSliceValue) Set(s string) (err error) { // String implements the [flag.Value] interface for *intSliceValue. func (i *intSliceValue) String() (out string) { + if i == nil || i.values == nil { + return "" + } + sb := &strings.Builder{} for idx, v := range *i.values { if idx > 0 { @@ -144,6 +141,10 @@ func (i *stringSliceValue) Set(s string) (err error) { // String implements the [flag.Value] interface for *stringSliceValue. func (i *stringSliceValue) String() (out string) { + if i == nil || i.values == nil { + return "" + } + sb := &strings.Builder{} for idx, v := range *i.values { if idx > 0 {