MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / loadJSONFile

Function loadJSONFile

cmd/wsh/cmd/wshcmd-setmeta.go:34–60  ·  view source on GitHub ↗
(filepath string)

Source from the content-addressed store, hash-verified

32}
33
34func loadJSONFile(filepath string) (map[string]interface{}, error) {
35 var data []byte
36 var err error
37
38 if filepath == "-" {
39 data, err = io.ReadAll(os.Stdin)
40 if err != nil {
41 return nil, fmt.Errorf("reading from stdin: %v", err)
42 }
43 } else {
44 data, err = os.ReadFile(filepath)
45 if err != nil {
46 return nil, fmt.Errorf("reading JSON file: %v", err)
47 }
48 }
49
50 var result map[string]interface{}
51 if err := json.Unmarshal(data, &result); err != nil {
52 return nil, fmt.Errorf("parsing JSON file: %v", err)
53 }
54
55 if result == nil {
56 return nil, fmt.Errorf("JSON file must contain an object, not null")
57 }
58
59 return result, nil
60}
61
62func parseMetaValue(setVal string) (any, error) {
63 if setVal == "" || setVal == "null" {

Callers 1

setMetaRunFunction · 0.85

Calls 2

ReadFileMethod · 0.80
ReadAllMethod · 0.45

Tested by

no test coverage detected