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

Accept multi-value input on slice flags #1238

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

Accept multi-value input on slice flags #1238

vipally opened this issue Feb 8, 2021 · 2 comments · Fixed by #1241
Labels
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
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

Multi values on slice flags were acceted on ENV values input but flag values accept only single ones.

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,parsed2", "--stringSclice", "parsed3,parsed4",
		"--float64Sclice", "13.3,14.4", "--float64Sclice", "15.5,16.6",
		"--int64Sclice", "13,14", "--int64Sclice", "15,16",
		"--intSclice", "13,14", "--intSclice", "15,16",
	}
	os.Setenv("ENV_CLI_FLOAT64_SLICE", "23.3,24.4")
	app := cli.NewApp()
	app.Name = "multi_values"
	app.Flags = []cli.Flag{
		&cli.StringSliceFlag{Name: "stringSclice"},
		&cli.Float64SliceFlag{Name: "float64Sclice", EnvVars: []string{"ENV_CLI_FLOAT64_SLICE"}},
		&cli.Int64SliceFlag{Name: "int64Sclice"},
		&cli.IntSliceFlag{Name: "intSclice"},
	}
	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)
}

// Incorrect Usage. invalid value "13.3,14.4" for flag -float64Sclice: strconv.ParseFloat: parsing "13.3,14.4": invalid syntax

Observed behavior

Incorrect Usage. invalid value "13.3,14.4" for flag -float64Sclice: strconv.ParseFloat: parsing "13.3,14.4": invalid syntax

Expected behavior

Output:

0-float64Sclice cli.Float64Slice{slice:[]float64{13.3, 14.4, 15.5, 16.6}, hasBeenSet:true}
1-int64Sclice cli.Int64Slice{slice:[]int64{13, 14, 15, 16}, hasBeenSet:true}
2-intSclice cli.IntSlice{slice:[]int{13, 14, 15, 16}, hasBeenSet:true}
3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed2", "parsed3", "parsed4"}, 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
@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
@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: accept multi-value input on sclice flags Accept multi-value input on slice flags Apr 23, 2022
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/triage maintainers still need to look into this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants