-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
30 lines (26 loc) · 915 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package conf
// Option represents a change to the default parsing
type Option func(c *context)
// WithConfigFile tells parse to attempt to read from the specified file, if it
// is found.
func WithConfigFile(filename string) Option {
return func(c *context) {
c.confFile = filename
}
}
// WithConfigFileFlag tells parse to look for a flag called `flagname` and, if
// it is found, to attempt to load configuration from this file. If the flag
// is specified, it will override the value provided to WithConfigFile, if that
// has been specified. If the file is not found, the program will exit with an
// error.
func WithConfigFileFlag(flagname string) Option {
return func(c *context) {
c.confFlag = flagname
}
}
// WithSource adds additional configuration sources for configuration parsing
func WithSource(source Source) Option {
return func(c *context) {
c.sources = append(c.sources, source)
}
}