MCPcopy Create free account
hub / github.com/cli/cli / getVariablesFromOptions

Function getVariablesFromOptions

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

Source from the content-addressed store, hash-verified

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

Callers 2

setRunFunction · 0.85

Calls 5

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

Tested by 1