-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathoption.go
45 lines (39 loc) · 1.28 KB
/
option.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2025 The konf authors
// Use of this source code is governed by a MIT license found in the LICENSE file.
package flag
import (
"flag"
)
// WithPrefix provides the prefix used when loading flags.
// Only flags with names that start with the prefix will be loaded.
//
// For example, if the prefix is "server", only flags whose names start with "server" will be loaded.
// By default, it has no prefix which loads all flags.
func WithPrefix(prefix string) Option {
return func(options *options) {
options.prefix = prefix
}
}
// WithFlagSet provides the [flag.FlagSet] that loads configuration from.
//
// The default flag set is [flag.CommandLine].
func WithFlagSet(set *flag.FlagSet) Option {
return func(options *options) {
options.set = set
}
}
// WithNameSplitter provides the function used to split flag names into nested keys.
// If it returns an nil/[]string{}/[]string{""}, the variable will be ignored.
//
// For example, with the default splitter, an flag name like "parent.child.key"
// would be split into "parent", "child", and "key".
func WithNameSplitter(splitter func(string) []string) Option {
return func(options *options) {
options.splitter = splitter
}
}
type (
// Option configures the a Flag with specific options.
Option func(*options)
options Flag
)