Skip to content

Commit dec6937

Browse files
committed
Fixing a bug that occured when using RegisterSimpleType with a type that aliases a simple type
1 parent 3af1ed6 commit dec6937

File tree

8 files changed

+56
-53
lines changed

8 files changed

+56
-53
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# go-flagsfiller
22

3-
[![](https://godoc.org/github.com/itzg/go-flagsfiller?status.svg)](https://godoc.org/github.com/itzg/go-flagsfiller)
4-
[![](https://img.shields.io/badge/go.dev-module-007D9C)](https://pkg.go.dev/github.com/itzg/go-flagsfiller)
3+
[![](https://godoc.org/github.com/nextmv-io/go-flagsfiller?status.svg)](https://godoc.org/github.com/nextmv-io/go-flagsfiller)
4+
[![](https://img.shields.io/badge/go.dev-module-007D9C)](https://pkg.go.dev/github.com/nextmv-io/go-flagsfiller)
55

66
Bring your own struct and make Go's flag package pleasant to use.
77

88
## Install
99

1010
```
11-
go get github.com/itzg/go-flagsfiller
11+
go get github.com/nextmv-io/go-flagsfiller
1212
```
1313

1414
## Import
1515

1616
```go
17-
import "github.com/itzg/go-flagsfiller"
17+
import "github.com/nextmv-io/go-flagsfiller"
1818
```
1919

2020
## Features
@@ -46,7 +46,7 @@ package main
4646
import (
4747
"flag"
4848
"fmt"
49-
"github.com/itzg/go-flagsfiller"
49+
"github.com/nextmv-io/go-flagsfiller"
5050
"log"
5151
"time"
5252
)
@@ -191,4 +191,4 @@ func (c *loadFromGitCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...i
191191
```
192192
## More information
193193
194-
[Refer to the GoDocs](https://godoc.org/github.com/itzg/go-flagsfiller) for more information about this module.
194+
[Refer to the GoDocs](https://godoc.org/github.com/nextmv-io/go-flagsfiller) for more information about this module.

addtional_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/itzg/go-flagsfiller"
10+
"github.com/nextmv-io/go-flagsfiller"
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313
)

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package flagsfiller_test
33
import (
44
"flag"
55
"fmt"
6-
"github.com/itzg/go-flagsfiller"
6+
"github.com/nextmv-io/go-flagsfiller"
77
"log"
88
"time"
99
)
@@ -13,7 +13,7 @@ func Example() {
1313
Host string `default:"localhost" usage:"The remote host"`
1414
Enabled bool `default:"true" usage:"Turn it on"`
1515
Automatic bool `default:"false" usage:"Make it automatic" aliases:"a"`
16-
Retries int `default:"1" usage:"Retry" aliases:"r,t"`
16+
Retries int `default:"1" usage:"Retry" aliases:"r,t"`
1717
Timeout time.Duration `default:"5s" usage:"How long to wait"`
1818
}
1919

examples/flagsfiller-example/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"github.com/itzg/go-flagsfiller"
6+
"github.com/nextmv-io/go-flagsfiller"
77
"log"
88
"time"
99
)
1010

1111
type Config struct {
12-
Host string `default:"localhost" usage:"The remote host"`
13-
DebugEnabled bool `default:"true" usage:"Show debugs"`
14-
MaxTimeout time.Duration `default:"5s" usage:"How long to wait"`
15-
IgnoreCertificate bool `default:"false" usage:"Make it automatic" aliase:"k"`
16-
Feature struct {
12+
Host string `default:"localhost" usage:"The remote host"`
13+
DebugEnabled bool `default:"true" usage:"Show debugs"`
14+
MaxTimeout time.Duration `default:"5s" usage:"How long to wait"`
15+
IgnoreCertificate bool `default:"false" usage:"Make it automatic" aliase:"k"`
16+
Feature struct {
1717
Faster bool `usage:"Go faster"`
1818
LudicrousSpeed bool `usage:"Go even faster"`
1919
}

flagset.go

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -198,54 +198,57 @@ func (f *FlagSetFiller) processField(flagSet *flag.FlagSet, fieldRef interface{}
198198
}
199199
// go through all supported structs
200200
if isSupportedStruct(fieldRef) {
201-
handler := extendedTypes[getTypeName(t)]
201+
name := getTypeName(t)
202+
handler := extendedTypes[name]
202203
err = handler(tag, fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
204+
if err != nil {
205+
return fmt.Errorf("failed to process %s: %w", name, err)
206+
}
207+
} else {
208+
switch {
209+
case t.Kind() == reflect.String:
210+
f.processString(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
203211

204-
}
205-
206-
switch {
207-
case t.Kind() == reflect.String:
208-
f.processString(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
209-
210-
case t.Kind() == reflect.Bool:
211-
err = f.processBool(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
212+
case t.Kind() == reflect.Bool:
213+
err = f.processBool(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
212214

213-
case t.Kind() == reflect.Float64:
214-
err = f.processFloat64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
215+
case t.Kind() == reflect.Float64:
216+
err = f.processFloat64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
215217

216-
// NOTE check time.Duration before int64 since it is aliasesed from int64
217-
case t == durationType, fieldType == "duration":
218-
err = f.processDuration(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
218+
// NOTE check time.Duration before int64 since it is aliasesed from int64
219+
case t == durationType, fieldType == "duration":
220+
err = f.processDuration(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
219221

220-
case t.Kind() == reflect.Int64:
221-
err = f.processInt64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
222+
case t.Kind() == reflect.Int64:
223+
err = f.processInt64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
222224

223-
case t.Kind() == reflect.Int:
224-
err = f.processInt(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
225+
case t.Kind() == reflect.Int:
226+
err = f.processInt(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
225227

226-
case t.Kind() == reflect.Uint64:
227-
err = f.processUint64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
228+
case t.Kind() == reflect.Uint64:
229+
err = f.processUint64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
228230

229-
case t.Kind() == reflect.Uint:
230-
err = f.processUint(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
231+
case t.Kind() == reflect.Uint:
232+
err = f.processUint(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
231233

232-
case t == stringSliceType, fieldType == "stringSlice":
233-
var override bool
234-
if overrideValue, exists := tag.Lookup("override-value"); exists {
235-
if value, err := strconv.ParseBool(overrideValue); err == nil {
236-
override = value
234+
case t == stringSliceType, fieldType == "stringSlice":
235+
var override bool
236+
if overrideValue, exists := tag.Lookup("override-value"); exists {
237+
if value, err := strconv.ParseBool(overrideValue); err == nil {
238+
override = value
239+
}
237240
}
238-
}
239-
f.processStringSlice(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, override, aliases)
241+
f.processStringSlice(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, override, aliases)
240242

241-
case t == stringToStringMapType, fieldType == "stringMap":
242-
f.processStringToStringMap(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
243+
case t == stringToStringMapType, fieldType == "stringMap":
244+
f.processStringToStringMap(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
243245

244-
// ignore any other types
245-
}
246+
// ignore any other types
247+
}
246248

247-
if err != nil {
248-
return err
249+
if err != nil {
250+
return err
251+
}
249252
}
250253

251254
if !f.options.noSetFromEnv && envName != "" {

flagset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/iancoleman/strcase"
12-
"github.com/itzg/go-flagsfiller"
12+
"github.com/nextmv-io/go-flagsfiller"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
1515
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/itzg/go-flagsfiller
1+
module github.com/nextmv-io/go-flagsfiller
22

33
go 1.19
44

options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package flagsfiller_test
22

33
import (
44
"fmt"
5-
"github.com/itzg/go-flagsfiller"
5+
"github.com/nextmv-io/go-flagsfiller"
66
)
77

88
func ExampleCompositeRenamer() {

0 commit comments

Comments
 (0)