MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / loadConfigFor

Function loadConfigFor

cmd/crowdsec-cli/main.go:95–120  ·  view source on GitHub ↗

loadConfigFor loads the configuration file for the given sub-command. If the sub-command does not need it, it returns a default configuration.

(command string)

Source from the content-addressed store, hash-verified

93// loadConfigFor loads the configuration file for the given sub-command.
94// If the sub-command does not need it, it returns a default configuration.
95func loadConfigFor(command string) (*csconfig.Config, string, error) {
96 noNeedConfig := []string{
97 "doc",
98 "help",
99 "completion",
100 "version",
101 }
102
103 if !slices.Contains(noNeedConfig, command) {
104 log.Debugf("Using %s as configuration file", ConfigFilePath)
105
106 config, merged, err := csconfig.NewConfig(ConfigFilePath, false, false, true)
107 if err != nil {
108 return nil, "", err
109 }
110
111 // set up directory for trace files
112 if err := trace.Init(filepath.Join(config.ConfigPaths.DataDir, "trace")); err != nil {
113 return nil, "", fmt.Errorf("while setting up trace directory: %w", err)
114 }
115
116 return config, merged, nil
117 }
118
119 return csconfig.NewDefaultConfig(), "", nil
120}
121
122// initialize is called before the subcommand is executed.
123func (cli *cliRoot) initialize() error {

Callers 1

initializeMethod · 0.85

Calls 3

NewConfigFunction · 0.92
NewDefaultConfigFunction · 0.92
InitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…