MCPcopy Create free account
hub / github.com/docker/cli / makeEnv

Method makeEnv

cli/command/service/opts.go:683–703  ·  view source on GitHub ↗

makeEnv gets the environment variables from the command line options and returns a slice of strings to use in the service spec when doing ToService

()

Source from the content-addressed store, hash-verified

681// makeEnv gets the environment variables from the command line options and
682// returns a slice of strings to use in the service spec when doing ToService
683func (options *serviceOptions) makeEnv() ([]string, error) {
684 envVariables, err := opts.ReadKVEnvStrings(options.envFile.GetSlice(), options.env.GetSlice())
685 if err != nil {
686 return nil, err
687 }
688 currentEnv := make([]string, 0, len(envVariables))
689 for _, env := range envVariables { // need to process each var, in order
690 k, _, _ := strings.Cut(env, "=")
691 for i, current := range currentEnv { // remove duplicates
692 if current == env {
693 continue // no update required, may hide this behind flag to preserve order of envVariables
694 }
695 if strings.HasPrefix(current, k+"=") {
696 currentEnv = append(currentEnv[:i], currentEnv[i+1:]...)
697 }
698 }
699 currentEnv = append(currentEnv, env)
700 }
701
702 return currentEnv, nil
703}
704
705// ToService takes the set of flags passed to the command and converts them
706// into a service spec.

Callers 1

ToServiceMethod · 0.95

Calls 1

GetSliceMethod · 0.80

Tested by

no test coverage detected