Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: itzg/go-flagsfiller
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nextmv-io/go-flagsfiller
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: stable
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 8 files changed
  • 1 contributor

Commits on Nov 2, 2023

  1. Fixing a bug that occured when using RegisterSimpleType with a type t…

    …hat aliases a simple type
    larsbeck committed Nov 2, 2023
    Copy the full SHA
    dec6937 View commit details
Showing with 56 additions and 53 deletions.
  1. +6 −6 README.md
  2. +1 −1 addtional_test.go
  3. +2 −2 example_test.go
  4. +6 −6 examples/flagsfiller-example/main.go
  5. +38 −35 flagset.go
  6. +1 −1 flagset_test.go
  7. +1 −1 go.mod
  8. +1 −1 options_test.go
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# go-flagsfiller

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

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

## Install

```
go get github.com/itzg/go-flagsfiller
go get github.com/nextmv-io/go-flagsfiller
```

## Import

```go
import "github.com/itzg/go-flagsfiller"
import "github.com/nextmv-io/go-flagsfiller"
```

## Features
@@ -46,7 +46,7 @@ package main
import (
"flag"
"fmt"
"github.com/itzg/go-flagsfiller"
"github.com/nextmv-io/go-flagsfiller"
"log"
"time"
)
@@ -191,4 +191,4 @@ func (c *loadFromGitCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...i
```
## More information
[Refer to the GoDocs](https://godoc.org/github.com/itzg/go-flagsfiller) for more information about this module.
[Refer to the GoDocs](https://godoc.org/github.com/nextmv-io/go-flagsfiller) for more information about this module.
2 changes: 1 addition & 1 deletion addtional_test.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/itzg/go-flagsfiller"
"github.com/nextmv-io/go-flagsfiller"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package flagsfiller_test
import (
"flag"
"fmt"
"github.com/itzg/go-flagsfiller"
"github.com/nextmv-io/go-flagsfiller"
"log"
"time"
)
@@ -13,7 +13,7 @@ func Example() {
Host string `default:"localhost" usage:"The remote host"`
Enabled bool `default:"true" usage:"Turn it on"`
Automatic bool `default:"false" usage:"Make it automatic" aliases:"a"`
Retries int `default:"1" usage:"Retry" aliases:"r,t"`
Retries int `default:"1" usage:"Retry" aliases:"r,t"`
Timeout time.Duration `default:"5s" usage:"How long to wait"`
}

12 changes: 6 additions & 6 deletions examples/flagsfiller-example/main.go
Original file line number Diff line number Diff line change
@@ -3,17 +3,17 @@ package main
import (
"flag"
"fmt"
"github.com/itzg/go-flagsfiller"
"github.com/nextmv-io/go-flagsfiller"
"log"
"time"
)

type Config struct {
Host string `default:"localhost" usage:"The remote host"`
DebugEnabled bool `default:"true" usage:"Show debugs"`
MaxTimeout time.Duration `default:"5s" usage:"How long to wait"`
IgnoreCertificate bool `default:"false" usage:"Make it automatic" aliase:"k"`
Feature struct {
Host string `default:"localhost" usage:"The remote host"`
DebugEnabled bool `default:"true" usage:"Show debugs"`
MaxTimeout time.Duration `default:"5s" usage:"How long to wait"`
IgnoreCertificate bool `default:"false" usage:"Make it automatic" aliase:"k"`
Feature struct {
Faster bool `usage:"Go faster"`
LudicrousSpeed bool `usage:"Go even faster"`
}
73 changes: 38 additions & 35 deletions flagset.go
Original file line number Diff line number Diff line change
@@ -198,54 +198,57 @@ func (f *FlagSetFiller) processField(flagSet *flag.FlagSet, fieldRef interface{}
}
// go through all supported structs
if isSupportedStruct(fieldRef) {
handler := extendedTypes[getTypeName(t)]
name := getTypeName(t)
handler := extendedTypes[name]
err = handler(tag, fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
if err != nil {
return fmt.Errorf("failed to process %s: %w", name, err)
}
} else {
switch {
case t.Kind() == reflect.String:
f.processString(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

}

switch {
case t.Kind() == reflect.String:
f.processString(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

case t.Kind() == reflect.Bool:
err = f.processBool(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
case t.Kind() == reflect.Bool:
err = f.processBool(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

case t.Kind() == reflect.Float64:
err = f.processFloat64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
case t.Kind() == reflect.Float64:
err = f.processFloat64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

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

case t.Kind() == reflect.Int64:
err = f.processInt64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
case t.Kind() == reflect.Int64:
err = f.processInt64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

case t.Kind() == reflect.Int:
err = f.processInt(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
case t.Kind() == reflect.Int:
err = f.processInt(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

case t.Kind() == reflect.Uint64:
err = f.processUint64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
case t.Kind() == reflect.Uint64:
err = f.processUint64(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

case t.Kind() == reflect.Uint:
err = f.processUint(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
case t.Kind() == reflect.Uint:
err = f.processUint(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

case t == stringSliceType, fieldType == "stringSlice":
var override bool
if overrideValue, exists := tag.Lookup("override-value"); exists {
if value, err := strconv.ParseBool(overrideValue); err == nil {
override = value
case t == stringSliceType, fieldType == "stringSlice":
var override bool
if overrideValue, exists := tag.Lookup("override-value"); exists {
if value, err := strconv.ParseBool(overrideValue); err == nil {
override = value
}
}
}
f.processStringSlice(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, override, aliases)
f.processStringSlice(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, override, aliases)

case t == stringToStringMapType, fieldType == "stringMap":
f.processStringToStringMap(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)
case t == stringToStringMapType, fieldType == "stringMap":
f.processStringToStringMap(fieldRef, hasDefaultTag, tagDefault, flagSet, renamed, usage, aliases)

// ignore any other types
}
// ignore any other types
}

if err != nil {
return err
if err != nil {
return err
}
}

if !f.options.noSetFromEnv && envName != "" {
2 changes: 1 addition & 1 deletion flagset_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
"time"

"github.com/iancoleman/strcase"
"github.com/itzg/go-flagsfiller"
"github.com/nextmv-io/go-flagsfiller"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/itzg/go-flagsfiller
module github.com/nextmv-io/go-flagsfiller

go 1.19

2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ package flagsfiller_test

import (
"fmt"
"github.com/itzg/go-flagsfiller"
"github.com/nextmv-io/go-flagsfiller"
)

func ExampleCompositeRenamer() {