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

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

Open
bluntelk opened this issue Jan 2, 2025 · 1 comment

Comments

@bluntelk
Copy link

bluntelk commented Jan 2, 2025

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
)
@bluntelk bluntelk changed the title TOML, JSON and YAML return values do not implement cli.ValueSource TOML, JSON and YAML return values do not implement cli.ValueSource needed for cli.NewValueSourceChain() Jan 2, 2025
@bluntelk bluntelk changed the title TOML, JSON and YAML return values do not implement cli.ValueSource needed for cli.NewValueSourceChain() TOML, JSON and YAML return values do not implement cli.ValueSource needed for cli.NewValueSourceChain() Jan 2, 2025
@dearchap
Copy link
Contributor

@bluntelk We've been re-arranging some code in this repo . Can you try with the latest version like this ?

package main

import (
	"context"
	"log/slog"
	"os"

	ajson "github.com/urfave/cli-altsrc/json"
	"github.com/urfave/cli/v3"
)

func main() {
	app := cli.Command{
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name: "test",
				Sources: cli.NewValueSourceChain(
					cli.EnvVar("TEST"),
					ajson.JSON("test", "./config.json"),
				),
			},
		},
	}
	if err := app.Run(context.Background(), os.Args); err != nil {
		slog.Error("Error running app", "err", err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants