Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slice flag value don't append to default values from ENV or file #1239

Closed
3 tasks done
vipally opened this issue Feb 8, 2021 · 4 comments · Fixed by #1240
Closed
3 tasks done

slice flag value don't append to default values from ENV or file #1239

vipally opened this issue Feb 8, 2021 · 4 comments · Fixed by #1240
Assignees
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/claimed someone has claimed this issue
Milestone

Comments

@vipally
Copy link
Contributor

vipally commented Feb 8, 2021

my urfave/cli version is

v2.3.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 automatically downloading the latest version.

Describe the bug

Slice flag value don't append to default values from ENV or file.

To reproduce

I have put the test code here

package main

import (
	"fmt"
	"os"

	"github.com/urfave/cli/v2"
)

func main() {
	os.Args = []string{"multi_values",
		"--stringSclice", "parsed1", "--stringSclice", "parsed3",
		"--float64Sclice", "13.3", "--float64Sclice", "15.5",
		"--int64Sclice", "13", "--int64Sclice", "15",
		"--intSclice", "13", "--intSclice", "15",
	}
	os.Setenv("ENV_CLI_STRING_SLICE", "foo,bar")
	os.Setenv("ENV_CLI_FLOAT64_SLICE", "23.3,24.4")
	os.Setenv("ENV_CLI_INT64_SLICE", "23,24")
	os.Setenv("ENV_CLI_INT_SLICE", "23,24")
	app := cli.NewApp()
	app.Name = "multi_values"
	app.Flags = []cli.Flag{
		&cli.StringSliceFlag{Name: "stringSclice", EnvVars: []string{"ENV_CLI_STRING_SLICE"}},
		&cli.Float64SliceFlag{Name: "float64Sclice", EnvVars: []string{"ENV_CLI_FLOAT64_SLICE"}},
		&cli.Int64SliceFlag{Name: "int64Sclice", EnvVars: []string{"ENV_CLI_INT64_SLICE"}},
		&cli.IntSliceFlag{Name: "intSclice", EnvVars: []string{"ENV_CLI_INT_SLICE"}},
	}
	app.Action = func(ctx *cli.Context) error {
		for i, v := range ctx.FlagNames() {
			fmt.Printf("%d-%s %#v\n", i, v, ctx.Value(v))
		}
		return ctx.Err()
	}

	_ = app.Run(os.Args)

	// bug: slice flag value don't append to default values from ENV or file
	/*
		0-float64Sclice cli.Float64Slice{slice:[]float64{23.3, 24.4, 13.3, 15.5}, hasBeenSet:true}	// bug: expect []float64{13.3, 15.5}
		1-int64Sclice cli.Int64Slice{slice:[]int64{23, 24, 13, 15}, hasBeenSet:true}				// bug: expect []int64{13, 15}
		2-intSclice cli.IntSlice{slice:[]int{23, 24, 13, 15}, hasBeenSet:true}						// bug: expect []int{13, 15}
		3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed3"}, hasBeenSet:true}
	*/
}

Observed behavior

0-float64Sclice cli.Float64Slice{slice:[]float64{23.3, 24.4, 13.3, 15.5}, hasBeenSet:true}
1-int64Sclice cli.Int64Slice{slice:[]int64{23, 24, 13, 15}, hasBeenSet:true}
2-intSclice cli.IntSlice{slice:[]int{23, 24, 13, 15}, hasBeenSet:true}
3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed3"}, hasBeenSet:true}

Expected behavior

0-float64Sclice cli.Float64Slice{slice:[]float64{13.3, 15.5}, hasBeenSet:true}
1-int64Sclice cli.Int64Slice{slice:[]int64{13, 15}, hasBeenSet:true}
2-intSclice cli.IntSlice{slice:[]int{13, 15}, hasBeenSet:true}
3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed3"}, hasBeenSet:true}

Additional context

I have put the test code here

Want to fix this yourself?

We'd love to have more contributors on this project! If the fix for this bug is easily explained and very small, free free to create a pull request for it.

Run go version and paste its output here

go version go1.15.6 windows/amd64

Run go env and paste its output here

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\ally\AppData\Local\go-build
set GOENV=C:\Users\ally\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\ally\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\ally\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ally\AppData\Local\Temp\go-build790788990=/tmp/go-build -gno-record-gcc-switches
@vipally vipally added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Feb 8, 2021
vipally added a commit to vipally/cli that referenced this issue Feb 8, 2021
@coilysiren
Copy link
Member

I'm slightly worried that this might be a breaking change for someone somewhere, but at a basic level the expected behavior you describe is definitely correct 👍🏼

@coilysiren coilysiren added status/claimed someone has claimed this issue and removed status/triage maintainers still need to look into this labels Feb 10, 2021
@stale
Copy link

stale bot commented Jun 2, 2021

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Jun 2, 2021
@stale
Copy link

stale bot commented Jul 4, 2021

Closing this as it has become stale.

@stale stale bot closed this as completed Jul 4, 2021
rliebz pushed a commit that referenced this issue Jul 7, 2021
…r file (#1240)

* fix #1239: slice flag value don't append to default values from ENV or file

* remove test code
@meatballhat meatballhat reopened this Apr 22, 2022
@meatballhat meatballhat removed the status/stale stale due to the age of it's last update label Apr 22, 2022
@meatballhat meatballhat changed the title v2 bug: slice flag value don't append to default values from ENV or file slice flag value don't append to default values from ENV or file Apr 23, 2022
@meatballhat meatballhat added this to the Release 2.4.x milestone Apr 23, 2022
@meatballhat
Copy link
Member

Actually closed via #1240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/claimed someone has claimed this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants