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)
| 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. |
| 95 | func 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. |
| 123 | func (cli *cliRoot) initialize() error { |
no test coverage detected
searching dependent graphs…