Skip to content

TOML, JSON and YAML return values do not implement cli.ValueSource needed for cli.NewValueSourceChain() #13

@bluntelk

Description

@bluntelk

Hi there,

I am trying out the new v3 APIs and have run across a rough edge when following the documentation

URLs

The documentation says we can just use

cli.StringFlag{
        Sources: cli.ValueSourceChain{
           Chain: {
                EnvVars("APP_LANG"),
                Files("/path/to/foo"),
                altsrc.JSON("foo", "/path/to/"),
           }                
        },
}

but doing that we get errors like

cannot use (altsrc.JSON("foo", "/path/to/")) (value of type cli.ValueSourceChain) as cli.ValueSource value in argument to cli.NewValueSourceChain: cli.ValueSourceChain does not implement cli.ValueSource (method GoString has pointer receiver)

Example Program

package main

import (
	"context"
	altsrc "github.com/urfave/cli-altsrc/v3"
	"github.com/urfave/cli/v3"
	"log/slog"
	"os"
)

func main() {
	app := cli.Command{
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name: "test",
				Sources: cli.NewValueSourceChain(
					cli.EnvVar("TEST"),
					altsrc.JSON("test", "./config.json"),
				),
			},
		},
	}
	if err := app.Run(context.Background(), os.Args); err != nil {
		slog.Error("Error running app", "err", err)
	}
}
require (
	github.com/urfave/cli-altsrc/v3 v3.0.0-alpha2
	github.com/urfave/cli/v3 v3.0.0-beta1
)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions