MCPcopy Index your code
hub / github.com/coldbrewcloud/coldbrew-cli / Load

Function Load

config/load.go:12–46  ·  view source on GitHub ↗
(data []byte, configFormat string, defaultAppName string)

Source from the content-addressed store, hash-verified

10)
11
12func Load(data []byte, configFormat string, defaultAppName string) (*Config, error) {
13 conf := &Config{}
14 configFormat = strings.ToLower(configFormat)
15 switch configFormat {
16 case flags.GlobalFlagsConfigFileFormatYAML:
17 if err := conf.FromYAML(data); err != nil {
18 return nil, fmt.Errorf("Failed to read configuration in YAML: %s\n", err.Error())
19 }
20 case flags.GlobalFlagsConfigFileFormatJSON:
21 if err := conf.FromJSON(data); err != nil {
22 return nil, fmt.Errorf("Failed to read configuration in JSON: %s\n", err.Error())
23 }
24 default:
25 return nil, fmt.Errorf("Unsupported configuration format [%s]", configFormat)
26 }
27
28 // env
29 if conf.Env == nil {
30 conf.Env = make(map[string]string)
31 }
32
33 // merge with defaults: defaultAppName is used only if loaded configuration does not have app name
34 appName := conv.S(conf.Name)
35 if appName == "" {
36 appName = defaultAppName
37 }
38 conf.Defaults(DefaultConfig(appName))
39
40 // validation
41 if err := conf.Validate(); err != nil {
42 return nil, core.NewErrorExtraInfo(err, "https://github.com/coldbrewcloud/coldbrew-cli/wiki/Configuration-File")
43 }
44
45 return conf, nil
46}
47
48func (c *Config) Defaults(source *Config) {
49 if source == nil {

Callers 1

TestLoadFunction · 0.85

Calls 6

FromYAMLMethod · 0.95
FromJSONMethod · 0.95
DefaultsMethod · 0.95
ValidateMethod · 0.95
DefaultConfigFunction · 0.85
ErrorMethod · 0.80

Tested by 1

TestLoadFunction · 0.68