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 10, 2024
1 parent 2c6f533 commit ef58ba6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions internal/cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ef58ba6

Please sign in to comment.