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
()
| 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 |
| 683 | func (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. |