Skip to content

Commit

Permalink
cmd: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Sep 9, 2024
1 parent d4bc235 commit 2c6f533
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ 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)
}

*i = uint32Value(v)

return err
return nil
}

// String implements the [flag.Value] interface for *uint32Value.
func (i *uint32Value) String() (out string) {
return strconv.FormatInt(int64(*i), 10)
return strconv.Itoa(int(*i))
}

// float32Value is an float32 that can be defined as a flag for [flag.FlagSet].
Expand Down Expand Up @@ -71,7 +78,7 @@ var _ flag.Value = (*intSliceValue)(nil)

// Set implements the [flag.Value] interface for *intSliceValue.
func (i *intSliceValue) Set(s string) (err error) {
intVal, err := strconv.ParseInt(s, 0, 32)
v, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("parsing integer slice arg %q: %w", s, err)
}
Expand All @@ -81,7 +88,7 @@ func (i *intSliceValue) Set(s string) (err error) {
*i.values = []int{}
}

*i.values = append(*i.values, int(intVal))
*i.values = append(*i.values, v)

return nil
}
Expand Down

0 comments on commit 2c6f533

Please sign in to comment.