Skip to content

Commit 77a5fef

Browse files
authored
Merge pull request #1456 from dearchap/issue_1455
Fix:(issue_1455) Allow bool flags from input altsrc
2 parents b4df361 + 2e8c0e9 commit 77a5fef

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

altsrc/flag.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ func (f *BoolFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceConte
126126
if err != nil {
127127
return err
128128
}
129-
if value {
130-
for _, name := range f.Names() {
131-
_ = f.set.Set(name, strconv.FormatBool(value))
132-
}
129+
for _, name := range f.Names() {
130+
_ = f.set.Set(name, strconv.FormatBool(value))
133131
}
134132
}
135133
return nil

altsrc/json_command_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
const (
1313
fileName = "current.json"
14-
simpleJSON = `{"test": 15}`
14+
simpleJSON = `{"test": 15, "testb": false}`
1515
nestedJSON = `{"top": {"test": 15}}`
1616
)
1717

@@ -34,11 +34,16 @@ func TestCommandJSONFileTest(t *testing.T) {
3434
Action: func(c *cli.Context) error {
3535
val := c.Int("test")
3636
expect(t, val, 15)
37+
38+
valb := c.Bool("testb")
39+
expect(t, valb, false)
3740
return nil
3841
},
3942
Flags: []cli.Flag{
4043
NewIntFlag(&cli.IntFlag{Name: "test"}),
41-
&cli.StringFlag{Name: "load"}},
44+
&cli.StringFlag{Name: "load"},
45+
NewBoolFlag(&cli.BoolFlag{Name: "testb", Value: true}),
46+
},
4247
}
4348
command.Before = InitInputSourceWithContext(command.Flags, NewJSONSourceFromFlagFunc("load"))
4449
err := command.Run(c)

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ require (
99
gopkg.in/yaml.v3 v3.0.1
1010
)
1111

12-
require github.com/russross/blackfriday/v2 v2.1.0 // indirect
12+
require (
13+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
14+
golang.org/x/text v0.3.7 // indirect
15+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
66
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
77
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
88
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
9+
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
10+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
911
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1012
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1113
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)