Skip to content

[v3] how to chain multible Sources? #1842

Closed

Description

@6543

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 ?

Activity

  1. added
    area/v2
    kind/question
    status/triage
    on Dec 14, 2023
  2. added
    area/v3
    and removed
    area/v2
    on Dec 14, 2023
  3. dearchap commented on Dec 14, 2023

    @dearchap
    Contributor
    &cli.StringFlag{
    		Name:    "grpc-token",
    		Usage:   "server-agent shared token",
    		Sources: cli.ValueSourceChain{Chain: {cli.EnvVars("...."), cli.FileVars("...")},
    
  4. 6543 commented on Dec 14, 2023

    @6543
    ContributorAuthor

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

  5. added
    kind/feature
    on Dec 14, 2023
  6. 6543 commented on Dec 14, 2023

    @6543
    ContributorAuthor

    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?

  7. 6543 commented on Dec 14, 2023

    @6543
    ContributorAuthor
    &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 :/

  8. 6543 commented on Dec 14, 2023

    @6543
    ContributorAuthor
    &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!

  9. 6543 commented on Dec 14, 2023

    @6543
    ContributorAuthor

    would be a pull welcome to address this?

  10. dearchap commented on Dec 14, 2023

    @dearchap
    Contributor

    @6543 Sure that would be fine.

  11. dearchap commented on Dec 14, 2023

    @dearchap
    Contributor

    @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("...")}},
    
  12. dearchap commented on Dec 15, 2023

    @dearchap
    Contributor

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

  13. 6543 commented on Dec 16, 2023

    @6543
    ContributorAuthor

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

  14. 6543 commented on Dec 25, 2023

    @6543
    ContributorAuthor

    thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v3kind/featurekind/questionstatus/triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions