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

[v3] how to chain multible Sources? #1842

Closed
6543 opened this issue Dec 14, 2023 · 11 comments · Fixed by #1849
Closed

[v3] how to chain multible Sources? #1842

6543 opened this issue Dec 14, 2023 · 11 comments · Fixed by #1849
Labels
area/v3 relates to / is being considered for v3 kind/feature describes a code enhancement / feature request kind/question someone asking a question status/triage maintainers still need to look into this

Comments

@6543
Copy link

6543 commented Dec 14, 2023

I did expect something like:

cli.StringFlag{
        Sources: EnvVars("APP_LANG").Or(Files("/path/to/foo")),
}

or

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

as this is not practicable:

	&cli.StringFlag{
		Name:    "grpc-token",
		Usage:   "server-agent shared token",
		Sources: cli.ValueSourceChain{Chain: append(cli.Files(os.Getenv("WOODPECKER_AGENT_SECRET_FILE")).Chain,cli.EnvVars("WOODPECKER_AGENT_SECRET").Chain...)} ,
	},

or did I miss something ?

@6543 6543 added area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this labels Dec 14, 2023
@dearchap dearchap added area/v3 relates to / is being considered for v3 and removed area/v2 relates to / is being considered for v2 labels Dec 14, 2023
@dearchap
Copy link
Contributor

dearchap commented Dec 14, 2023

&cli.StringFlag{
		Name:    "grpc-token",
		Usage:   "server-agent shared token",
		Sources: cli.ValueSourceChain{Chain: {cli.EnvVars("...."), cli.FileVars("...")},

@6543
Copy link
Author

6543 commented Dec 14, 2023

hmm in this regards could we make this issue a feature request to add an function to .Chain() Sources ?

@dearchap dearchap added the kind/feature describes a code enhancement / feature request label Dec 14, 2023
@6543
Copy link
Author

6543 commented Dec 14, 2023

if you move it behind an interface you can refactor things more easy ...
e.g. the internal Chain field don't have to be exported ...

or what take do you have on this matter?

@6543
Copy link
Author

6543 commented Dec 14, 2023

&cli.StringFlag{
		Name:    "grpc-token",
		Usage:   "server-agent shared token",
		Sources: cli.ValueSourceChain{Chain: {cli.EnvVars("...."), cli.FileVars("...")},

this does not work as SourceChain gen func to return slices ... witch need to be append to return a slice
else you get a slice of slices :/

@6543
Copy link
Author

6543 commented Dec 14, 2023

&cli.StringFlag{
		Name:    "grpc-token",
		Usage:   "server-agent shared token",
		Sources: cli.ValueSourceChain{Chain: []cli.ValueSource{cli.Files("...").Chain[0], cli.EnvVars("...").Chain[0]}},

this works but I would call it an hack!

@6543
Copy link
Author

6543 commented Dec 14, 2023

would be a pull welcome to address this?

@dearchap
Copy link
Contributor

@6543 Sure that would be fine.

@dearchap
Copy link
Contributor

dearchap commented Dec 14, 2023

@6543 This PR fix should allow you to do

&cli.StringFlag{
		Name:    "grpc-token",
		Usage:   "server-agent shared token",
		Sources: cli.ValueSourceChain{Chain: []cli.ValueSource{cli.Files("..."), cli.EnvVars("...")}},

@dearchap
Copy link
Contributor

@6543 I had to withdraw the PR to think a bit more about this

@6543
Copy link
Author

6543 commented Dec 16, 2023

I might have time and submit some pull just as draft to get some ideas going :)

@6543
Copy link
Author

6543 commented Dec 25, 2023

thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v3 relates to / is being considered for v3 kind/feature describes a code enhancement / feature request kind/question someone asking a question status/triage maintainers still need to look into this
Projects
None yet
2 participants