MCPcopy Index your code
hub / github.com/cloudfoundry/cli / LoadConfig

Function LoadConfig

util/configv3/load_config.go:66–179  ·  view source on GitHub ↗

LoadConfig loads the config from the .cf/config.json and os.ENV. If the config.json does not exists, it will use a default config in its place. Takes in an optional FlagOverride, will only use the first one passed, that can override the given flag values. The '.cf' directory will be read in one of

(flags ...FlagOverride)

Source from the content-addressed store, hash-verified

64// 2. HOMEDRIVE\HOMEPATH\.cf if HOMEDRIVE or HOMEPATH is set
65// 3. USERPROFILE\.cf as the default
66func LoadConfig(flags ...FlagOverride) (*Config, error) {
67 err := removeOldTempConfigFiles()
68 if err != nil {
69 return nil, err
70 }
71
72 configFilePath := ConfigFilePath()
73
74 config := Config{
75 ConfigFile: JSONConfig{
76 ConfigVersion: CurrentConfigVersion,
77 Target: DefaultTarget,
78 ColorEnabled: DefaultColorEnabled,
79 PluginRepositories: []PluginRepository{{
80 Name: DefaultPluginRepoName,
81 URL: DefaultPluginRepoURL,
82 }},
83 },
84 }
85
86 var jsonError error
87
88 if _, err = os.Stat(configFilePath); err == nil || !os.IsNotExist(err) {
89 var file []byte
90 file, err = os.ReadFile(configFilePath)
91 if err != nil {
92 return nil, err
93 }
94
95 if len(file) == 0 {
96 // TODO: change this to not use translatableerror
97 jsonError = translatableerror.EmptyConfigError{FilePath: configFilePath}
98 } else {
99 var configFile JSONConfig
100 err = json.Unmarshal(file, &configFile)
101 if err != nil {
102 return nil, err
103 }
104 if configFile.ConfigVersion == CurrentConfigVersion {
105 config.ConfigFile = configFile
106 }
107 }
108 }
109
110 if config.ConfigFile.SSHOAuthClient == "" {
111 config.ConfigFile.SSHOAuthClient = DefaultSSHOAuthClient
112 }
113
114 if config.ConfigFile.UAAOAuthClient == "" {
115 config.ConfigFile.UAAOAuthClient = DefaultUAAOAuthClient
116 config.ConfigFile.UAAOAuthClientSecret = DefaultUAAOAuthClientSecret
117 }
118
119 config.ENV = EnvOverride{
120 BinaryName: filepath.Base(os.Args[0]),
121 CFColor: os.Getenv("CF_COLOR"),
122 CFDialTimeout: os.Getenv("CF_DIAL_TIMEOUT"),
123 CFLogLevel: os.Getenv("CF_LOG_LEVEL"),

Callers 15

GetConfigFunction · 0.92
SetConfigFunction · 0.92
initI18nFuncFunction · 0.92
IsPluginCommandFunction · 0.92
PluginCommandNamesFunction · 0.92
config_test.goFile · 0.92
locale_test.goFile · 0.85
GetCFConfigFunction · 0.85

Calls 4

loadPluginConfigMethod · 0.95
removeOldTempConfigFilesFunction · 0.85
ConfigFilePathFunction · 0.70
IsTerminalMethod · 0.65

Tested by

no test coverage detected