Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Integer negative numbers are returned zero when parsed from yaml file #1199

@renanqts

Description

@renanqts

my urfave/cli version is

v2.2.0

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the Github guide about searching.

Dependency Management

  • My project is using go modules.
  • My project is using vendoring.
  • My project is automatically downloading the latest version.
  • I am unsure of what my dependency management setup is.

Describe the bug

Loading int negative values from a YAML file using altsrc returns zero.

To reproduce

Parser an integer negative from an YAML file.
example:

        yaml file content:
        negative-number: -1

	app.Before = altsrc.InitInputSourceWithContext(
		flags,
		func(context *cli.Context) (altsrc.InputSourceContext, error) {
			if context.IsSet("load") {
				return altsrc.NewYamlSourceFromFile(context.String("load"))
			}

			return &altsrc.MapInputSource{}, nil
		},
	)

	app.Action = func(context *cli.Context) error {

		fmt.Print(context.Int("negative-number"))
		return nil
	}

Observed behavior

Zero value.

Expected behavior

the value that is defined in the variable of the YAML file.

Additional context

The issue seems to be related to this condition

if value > 0 {

Want to fix this yourself?

The condition mentioned above, should not be greater than zero. It can not be applied for negative values.

Run go version and paste its output here

go version go1.15.3 linux/amd64

Run go env and paste its output here

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/renanrodrigues/.cache/go-build"
GOENV="/home/renanrodrigues/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/renanrodrigues/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/renanrodrigues/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/renanrodrigues/repos/telegram-sender/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build269715800=/tmp/go-build -gno-record-gcc-switches"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2help wantedplease help if you can!kind/bugdescribes or fixes a bugstatus/confirmedconfirmed to be valid, but work has yet to start

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions