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

StringSliceFlag does not set destination when reading from yaml #1197

Closed
5 of 7 tasks
lburgazzoli opened this issue Oct 13, 2020 · 5 comments
Closed
5 of 7 tasks

StringSliceFlag does not set destination when reading from yaml #1197

lburgazzoli opened this issue Oct 13, 2020 · 5 comments
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

@lburgazzoli
Copy link

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

The Destination field of a StringSliceFlag is not set when reading from a YAML file

To reproduce

Create YAML file with the following content:

dependency:
  - mvn:g/a/v

Create a Go application with the following code:

package main

import (
	"fmt"
	"log"
	"os"

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

func main() {
	dependencies := &cli.StringSlice{}

	flags := []cli.Flag{
		altsrc.NewStringFlag(&cli.StringFlag{
			Name:  "config",
			Value: ".app-config.yaml",
		}),
		altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
			Name:        "dependency",
			Usage:       "dependency",
			Aliases:     []string{"d"},
			Destination: dependencies,
		}),
	}
	app := &cli.App{
		Name:   "kamel",
		Usage:  "kamel",
		Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("config")),
		Flags:  flags,
		Action: func(c *cli.Context) error {
			fmt.Println("context:", c.StringSlice("dependency"))
			fmt.Println("destination:", dependencies)
			return nil
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}
}

Observed behavior

This code will print:

context: [mvn:g/a/v]
destination: []

Expected behavior

the value read from the file and associated to the dependency flag should be available both via the context and the destination.

Run go version and paste its output here

go version go1.14.9 linux/amd64

Run go env and paste its output here

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/lburgazz/.cache/go-build"
GOENV="/home/lburgazz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/lburgazz/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/data/sfw/lang/go/1.14.9"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/data/sfw/lang/go/1.14.9/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/lburgazz/work/lb/dev/camel-k-cli/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-build629793049=/tmp/go-build -gno-record-gcc-switches"

@lburgazzoli lburgazzoli 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 Oct 13, 2020
@mikunalpha
Copy link

Trick?
Screenshot-20201206205830

@stale
Copy link

stale bot commented Mar 7, 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 Mar 7, 2021
@stale
Copy link

stale bot commented Apr 18, 2021

Closing this as it has become stale.

@stale stale bot closed this as completed Apr 18, 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: StringSliceFlag does not set destination when reading from yaml StringSliceFlag does not set destination when reading from yaml Apr 23, 2022
@dearchap
Copy link
Contributor

@lburgazzoli I have a draft PR which fixes this issue if you are interested in testing out. Thanks

@dearchap
Copy link
Contributor

Fixed. Please use latest release

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

No branches or pull requests

4 participants