OptionsAsEnvs converts the DevcontainerFeatures into a list of environment variables that can be used to set feature options. The format is FEATURE_ _OPTION_ = . For example, if the feature is: "ghcr.io/coder/devcontainer-features/code-server:1": { "port": 9090,
()
| 56 | // "CODE_SERVER". The version part (e.g. ":1") is removed, and dashes in |
| 57 | // the feature and option names are replaced with underscores. |
| 58 | func (f DevcontainerFeatures) OptionsAsEnvs() []string { |
| 59 | var env []string |
| 60 | for k, v := range f { |
| 61 | vv, ok := v.(map[string]any) |
| 62 | if !ok { |
| 63 | continue |
| 64 | } |
| 65 | // Take the last part of the key as the feature name/path. |
| 66 | k = k[strings.LastIndex(k, "/")+1:] |
| 67 | // Remove ":" and anything following it. |
| 68 | if idx := strings.Index(k, ":"); idx != -1 { |
| 69 | k = k[:idx] |
| 70 | } |
| 71 | k = strings.ReplaceAll(k, "-", "_") |
| 72 | for k2, v2 := range vv { |
| 73 | k2 = strings.ReplaceAll(k2, "-", "_") |
| 74 | env = append(env, fmt.Sprintf("FEATURE_%s_OPTION_%s=%s", strings.ToUpper(k), strings.ToUpper(k2), fmt.Sprintf("%v", v2))) |
| 75 | } |
| 76 | } |
| 77 | slices.Sort(env) |
| 78 | return env |
| 79 | } |
| 80 | |
| 81 | type DevcontainerConfiguration struct { |
| 82 | Customizations DevcontainerCustomizations `json:"customizations,omitempty"` |
no outgoing calls