MCPcopy Index your code
hub / github.com/coder/coder / parseParameterMapFile

Function parseParameterMapFile

cli/parameter.go:137–165  ·  view source on GitHub ↗
(parameterFile string)

Source from the content-addressed store, hash-verified

135}
136
137func parseParameterMapFile(parameterFile string) (map[string]string, error) {
138 parameterFileContents, err := os.ReadFile(parameterFile)
139 if err != nil {
140 return nil, err
141 }
142
143 mapStringInterface := make(map[string]interface{})
144 err = yaml.Unmarshal(parameterFileContents, &mapStringInterface)
145 if err != nil {
146 return nil, err
147 }
148
149 parameterMap := map[string]string{}
150 for k, v := range mapStringInterface {
151 switch val := v.(type) {
152 case string, bool, int:
153 parameterMap[k] = fmt.Sprintf("%v", val)
154 case []interface{}:
155 b, err := json.Marshal(&val)
156 if err != nil {
157 return nil, err
158 }
159 parameterMap[k] = string(b)
160 default:
161 return nil, xerrors.Errorf("invalid parameter type: %T", v)
162 }
163 }
164 return parameterMap, nil
165}
166
167// buildFlags contains options relating to troubleshooting provisioner jobs
168// and setting the reason for the workspace build.

Callers 2

prepWorkspaceBuildFunction · 0.85

Calls 4

ReadFileMethod · 0.65
UnmarshalMethod · 0.45
MarshalMethod · 0.45
ErrorfMethod · 0.45

Tested by 1