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

better example of how to use altsrc #807

Closed
l0k18 opened this issue Mar 18, 2019 · 2 comments
Closed

better example of how to use altsrc #807

l0k18 opened this issue Mar 18, 2019 · 2 comments

Comments

@l0k18
Copy link

l0k18 commented Mar 18, 2019

I had to look for quite a while to find something that was sufficiently clear that I felt confident I could use the feature. I found this, it looks quite new and even though it's half in chinese you can see how the thing works:

https://github.com/web-skeleton/skeleton

I also discovered that yaml at least v1 doesn't understand duration values. I switched to toml but I suspect yaml v2 understands durations?

What I have learned is it doesn't matter if the flag a config loads from is wrapped in an altsrc new flag (my configs contain their file location, for example) and this seems to be the best way to get a config to load from a file, but not directly from a flag string value (it uses it to construct one):

		Before: func(c *cli.Context) error {

			fmt.Println("loading configuration")
			Configure(&podConfig)
			if FileExists(*podConfig.ConfigFile) {

				inputSource, err := altsrc.NewTomlSourceFromFile(*podConfig.ConfigFile)

				if err != nil {
					fmt.Println("error -", err)
					panic(err)
				}
				return altsrc.ApplyInputSourceValues(c, inputSource, c.App.Flags)
			}
			return nil
		},
@johnwyles
Copy link

@l0k1verloren Please also look at: #800 #793 and PR's #802 #803

@coilysiren
Copy link
Member

Hiya! There's a known issue with the current implementation of the CLI, where altsrc is generally clunky and poorly documented. My current idea is that I'm going to move all of the altsrc functionality into the main package in some way, and that's how all of the "altsrc is weird and different???" issues people are having will get resolved. I'm tracking that work here => #833

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

3 participants