MCPcopy Create free account
hub / github.com/algolia/cli / readConfigFromFile

Function readConfigFromFile

pkg/cmd/shared/handler/indices/config.go:244–270  ·  view source on GitHub ↗
(cs *iostreams.ColorScheme, filePath string)

Source from the content-addressed store, hash-verified

242}
243
244func readConfigFromFile(cs *iostreams.ColorScheme, filePath string) (*ImportConfigJSON, error) {
245 var config *ImportConfigJSON
246
247 jsonFile, err := os.Open(filePath)
248 if err != nil {
249 return nil, fmt.Errorf("%s An error occurred when opening file: %w", cs.FailureIcon(), err)
250 }
251 defer jsonFile.Close()
252 byteValue, err := io.ReadAll(jsonFile)
253 if err != nil {
254 return nil, fmt.Errorf(
255 "%s An error occurred when reading JSON file: %w",
256 cs.FailureIcon(),
257 err,
258 )
259 }
260 err = json.Unmarshal(byteValue, &config)
261 if err != nil {
262 return nil, fmt.Errorf(
263 "%s An error occurred when parsing JSON file: %w",
264 cs.FailureIcon(),
265 err,
266 )
267 }
268
269 return config, nil
270}

Callers 2

AskImportConfigFunction · 0.85

Calls 3

FailureIconMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected