MCPcopy Index your code
hub / github.com/cortexproject/cortex / parseConfigFileParameter

Function parseConfigFileParameter

cmd/cortex/main.go:225–243  ·  view source on GitHub ↗

Parse -config.file and -config.expand-env option via separate flag set, to avoid polluting default one and calling flag.Parse on it twice.

(args []string)

Source from the content-addressed store, hash-verified

223
224// Parse -config.file and -config.expand-env option via separate flag set, to avoid polluting default one and calling flag.Parse on it twice.
225func parseConfigFileParameter(args []string) (configFile string, expandEnv bool) {
226 // ignore errors and any output here. Any flag errors will be reported by main flag.Parse() call.
227 fs := flag.NewFlagSet("", flag.ContinueOnError)
228 fs.SetOutput(io.Discard)
229
230 // usage not used in these functions.
231 fs.StringVar(&configFile, configFileOption, "", "")
232 fs.BoolVar(&expandEnv, configExpandENV, false, "")
233
234 // Try to find -config.file and -config.expand-env option in the flags. As Parsing stops on the first error, eg. unknown flag, we simply
235 // try remaining parameters until we find config flag, or there are no params left.
236 // (ContinueOnError just means that flag.Parse doesn't call panic or os.Exit, but it returns error, which we ignore)
237 for len(args) > 0 {
238 _ = fs.Parse(args)
239 args = args[1:]
240 }
241
242 return
243}
244
245// LoadConfig read YAML-formatted config from filename into cfg.
246func LoadConfig(filename string, expandENV bool, cfg *cortex.Config) error {

Callers 2

mainFunction · 0.85

Calls 1

ParseMethod · 0.80

Tested by 1