Skip to content

There are two problems when loading yaml (slice, Uint64 flags) #1592

@kjeom

Description

@kjeom

test.yaml

scope: 
  test: 
    - test1
    - test2
test: 
  temp: 
    test: 1

testYaml.go

func main() {
	flags := []cli.Flag{
		&cli.StringFlag{
			Name:  "config",
			Usage: "yaml config file name",
		},
		altsrc.NewUint64Flag(
			&cli.Uint64Flag{
				Name:        "test.temp.test",
				Aliases:     []string{},
				Value:       0,
				Destination: &test,
			},
		),
		altsrc.NewStringSliceFlag(
			&cli.StringSliceFlag{
				Name:    "scope.test",
				Aliases: []string{},
				EnvVars: []string{},
			},
		),
	}

	app := &cli.App{
		Flags:  flags,
		Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewYamlSourceFromFlagFunc("config")),
		Action: func(ctx *cli.Context) error {
			if ctx.IsSet("scope.test") {
				fmt.Println("true", ctx.StringSlice("scope.test"))
			} else {
				fmt.Println("false", ctx.StringSlice("scope.test"))
			}
			if ctx.IsSet("test.temp.test") {
				fmt.Println("true", ctx.Uint64("test.temp.test") {
			} else {
				fmt.Println("false", ctx.Uint64("test.temp.test")
			}
			return nil
		},
	}
	fmt.Println(app.Run(os.Args))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/questionsomeone asking a questionstatus/claimedsomeone has claimed this issuestatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions