MCPcopy
hub / github.com/cli/cli / getVariablesFromOptions

Function getVariablesFromOptions

pkg/cmd/variable/set/set.go:228–264  ·  view source on GitHub ↗
(opts *SetOptions)

Source from the content-addressed store, hash-verified

226}
227
228func getVariablesFromOptions(opts *SetOptions) (map[string]string, error) {
229 variables := make(map[string]string)
230
231 if opts.EnvFile != "" {
232 var r io.Reader
233 if opts.EnvFile == "-" {
234 defer opts.IO.In.Close()
235 r = opts.IO.In
236 } else {
237 f, err := os.Open(opts.EnvFile)
238 if err != nil {
239 return nil, fmt.Errorf("failed to open env file: %w", err)
240 }
241 defer f.Close()
242 r = f
243 }
244 envs, err := godotenv.Parse(r)
245 if err != nil {
246 return nil, fmt.Errorf("error parsing env file: %w", err)
247 }
248 if len(envs) == 0 {
249 return nil, fmt.Errorf("no variables found in file")
250 }
251 for key, value := range envs {
252 variables[key] = value
253 }
254 return variables, nil
255 }
256
257 body, err := getBody(opts)
258 if err != nil {
259 return nil, fmt.Errorf("did not understand variable body: %w", err)
260 }
261 variables[opts.VariableName] = body
262
263 return variables, nil
264}
265
266func getBody(opts *SetOptions) (string, error) {
267 if opts.Body != "" {

Callers 2

setRunFunction · 0.85

Calls 4

OpenMethod · 0.80
getBodyFunction · 0.70
CloseMethod · 0.65
ErrorfMethod · 0.65

Tested by 1