Merge pull request #1262 from dearchap/issue_1199
Allow -ve values for int, float & duration
This commit is contained in:
commit
59ec2a1d5a
@ -197,10 +197,8 @@ func (f *IntFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContex
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if value > 0 {
|
for _, name := range f.Names() {
|
||||||
for _, name := range f.Names() {
|
_ = f.set.Set(name, strconv.FormatInt(int64(value), 10))
|
||||||
_ = f.set.Set(name, strconv.FormatInt(int64(value), 10))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,10 +213,8 @@ func (f *DurationFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if value > 0 {
|
for _, name := range f.Names() {
|
||||||
for _, name := range f.Names() {
|
_ = f.set.Set(name, value.String())
|
||||||
_ = f.set.Set(name, value.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,11 +229,9 @@ func (f *Float64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceCo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if value > 0 {
|
floatStr := float64ToString(value)
|
||||||
floatStr := float64ToString(value)
|
for _, name := range f.Names() {
|
||||||
for _, name := range f.Names() {
|
_ = f.set.Set(name, floatStr)
|
||||||
_ = f.set.Set(name, floatStr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,6 +234,15 @@ func TestIntApplyInputSourceMethodSet(t *testing.T) {
|
|||||||
expect(t, 15, c.Int("test"))
|
expect(t, 15, c.Int("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIntApplyInputSourceMethodSetNegativeValue(t *testing.T) {
|
||||||
|
c := runTest(t, testApplyInputSource{
|
||||||
|
Flag: NewIntFlag(&cli.IntFlag{Name: "test"}),
|
||||||
|
FlagName: "test",
|
||||||
|
MapValue: -1,
|
||||||
|
})
|
||||||
|
expect(t, -1, c.Int("test"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestIntApplyInputSourceMethodContextSet(t *testing.T) {
|
func TestIntApplyInputSourceMethodContextSet(t *testing.T) {
|
||||||
c := runTest(t, testApplyInputSource{
|
c := runTest(t, testApplyInputSource{
|
||||||
Flag: NewIntFlag(&cli.IntFlag{Name: "test"}),
|
Flag: NewIntFlag(&cli.IntFlag{Name: "test"}),
|
||||||
@ -264,6 +273,15 @@ func TestDurationApplyInputSourceMethodSet(t *testing.T) {
|
|||||||
expect(t, 30*time.Second, c.Duration("test"))
|
expect(t, 30*time.Second, c.Duration("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDurationApplyInputSourceMethodSetNegativeValue(t *testing.T) {
|
||||||
|
c := runTest(t, testApplyInputSource{
|
||||||
|
Flag: NewDurationFlag(&cli.DurationFlag{Name: "test"}),
|
||||||
|
FlagName: "test",
|
||||||
|
MapValue: -30 * time.Second,
|
||||||
|
})
|
||||||
|
expect(t, -30*time.Second, c.Duration("test"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestDurationApplyInputSourceMethodContextSet(t *testing.T) {
|
func TestDurationApplyInputSourceMethodContextSet(t *testing.T) {
|
||||||
c := runTest(t, testApplyInputSource{
|
c := runTest(t, testApplyInputSource{
|
||||||
Flag: NewDurationFlag(&cli.DurationFlag{Name: "test"}),
|
Flag: NewDurationFlag(&cli.DurationFlag{Name: "test"}),
|
||||||
@ -294,6 +312,24 @@ func TestFloat64ApplyInputSourceMethodSet(t *testing.T) {
|
|||||||
expect(t, 1.3, c.Float64("test"))
|
expect(t, 1.3, c.Float64("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFloat64ApplyInputSourceMethodSetNegativeValue(t *testing.T) {
|
||||||
|
c := runTest(t, testApplyInputSource{
|
||||||
|
Flag: NewFloat64Flag(&cli.Float64Flag{Name: "test"}),
|
||||||
|
FlagName: "test",
|
||||||
|
MapValue: -1.3,
|
||||||
|
})
|
||||||
|
expect(t, -1.3, c.Float64("test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFloat64ApplyInputSourceMethodSetNegativeValueNotSet(t *testing.T) {
|
||||||
|
c := runTest(t, testApplyInputSource{
|
||||||
|
Flag: NewFloat64Flag(&cli.Float64Flag{Name: "test1"}),
|
||||||
|
FlagName: "test1",
|
||||||
|
// dont set map value
|
||||||
|
})
|
||||||
|
expect(t, 0.0, c.Float64("test1"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestFloat64ApplyInputSourceMethodContextSet(t *testing.T) {
|
func TestFloat64ApplyInputSourceMethodContextSet(t *testing.T) {
|
||||||
c := runTest(t, testApplyInputSource{
|
c := runTest(t, testApplyInputSource{
|
||||||
Flag: NewFloat64Flag(&cli.Float64Flag{Name: "test"}),
|
Flag: NewFloat64Flag(&cli.Float64Flag{Name: "test"}),
|
||||||
|
Loading…
Reference in New Issue
Block a user