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

Inconsistent slice behavior, Value/Destination not applied #1143

Closed
3 tasks done
erikwilson opened this issue May 21, 2020 · 5 comments
Closed
3 tasks done

Inconsistent slice behavior, Value/Destination not applied #1143

erikwilson opened this issue May 21, 2020 · 5 comments
Assignees
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/confirmed confirmed to be valid, but work has yet to start
Milestone

Comments

@erikwilson
Copy link

erikwilson commented May 21, 2020

my urfave/cli version is

2.2.0
Also impacts 1.22.4

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.

Describe the bug

Slice flags are missing a Destination part (except for StringSliceFlag), but when used with altsrc the values are not propagated.

To reproduce

code:

package main

import (
	"fmt"
	"os"

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

func main() {
	var (
		testInt         int
		testIntSlice    cli.IntSlice
		testStringSlice cli.StringSlice
	)

	flags := []cli.Flag{
		altsrc.NewIntFlag(&cli.IntFlag{
			Name:        "test-int",
			Aliases:     []string{"t"},
			Destination: &testInt,
		}),
		altsrc.NewIntSliceFlag(&cli.IntSliceFlag{
			Name:    "test-int-slice",
			Aliases: []string{"i"},
			Value:   &testIntSlice,
		}),
		altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
			Name:        "test-string-slice",
			Aliases:     []string{"s"},
			Destination: &testStringSlice,
		}),
		&cli.StringFlag{Name: "load"},
	}

	app := &cli.App{
		Action: func(c *cli.Context) error {
			fmt.Printf("Have test-int value: %v\n", testInt)
			fmt.Printf("Have test-int context: %v\n", c.Int("test-int"))
			fmt.Printf("Have test-int-slice value: %v\n", testIntSlice.Value())
			fmt.Printf("Have test-int-slice context: %v\n", c.IntSlice("test-int-slice"))
			fmt.Printf("Have test-string-slice value: %v\n", testStringSlice.Value())
			fmt.Printf("Have test-string-slice context: %v\n", c.StringSlice("test-string-slice"))
			return nil
		},
		Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("load")),
		Flags:  flags,
	}

	app.Run(os.Args)
}

config yaml:

test-int: 1
test-int-slice: [ 1, 2, 3 ]
test-string-slice: [ a, b, c ]

Observed behavior

GO111MODULE=on go run test.go --load conf 
Have test-int value: 1
Have test-int context: 1
Have test-int-slice value: []
Have test-int-slice context: [1 2 3]
Have test-string-slice value: []
Have test-string-slice context: [a b c]
GO111MODULE=on go run test.go --load conf -t 3 -i 7 -i 8 -i 9 -s a -s z
Have test-int value: 3
Have test-int context: 3
Have test-int-slice value: [7 8 9]
Have test-int-slice context: [7 8 9]
Have test-string-slice value: [a z]
Have test-string-slice context: [a z]

Expected behavior

GO111MODULE=on go run test.go --load conf 
Have test-int value: 1
Have test-int context: 1
Have test-int-slice value: [? ? ?]
Have test-int-slice context: [1 2 3]
Have test-string-slice value: [a b c]
Have test-string-slice context: [a b c]

Additional context

Possibly related issues: #1121, #1075

@erikwilson erikwilson 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 May 21, 2020
@stale
Copy link

stale bot commented Aug 21, 2020

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 Aug 21, 2020
@stale
Copy link

stale bot commented Sep 20, 2020

Closing this as it has become stale.

@stale stale bot closed this as completed Sep 20, 2020
@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 altsrc v2 bug: inconsistent slice behavior, Value/Destination not applied Inconsistent slice behavior, Value/Destination not applied Apr 23, 2022
@meatballhat meatballhat added this to the Release 2.4.x milestone Apr 23, 2022
@meatballhat meatballhat self-assigned this Apr 24, 2022
@meatballhat
Copy link
Member

@erikwilson Belated thank you for the lovely issue! I'm working on a fix now 👍🏼

@dearchap
Copy link
Contributor

See PR#1495

@dearchap
Copy link
Contributor

Fixed in 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/confirmed confirmed to be valid, but work has yet to start
Projects
None yet
Development

No branches or pull requests

3 participants