MCPcopy Create free account
hub / github.com/coder/envbuilder / substitute

Function substitute

devcontainer/devcontainer.go:97–123  ·  view source on GitHub ↗

Spec for variable substitutions: https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson

(varExpr string, workspaceFolder string, lookupEnv func(string) (string, bool))

Source from the content-addressed store, hash-verified

95// Spec for variable substitutions:
96// https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson
97func substitute(varExpr string, workspaceFolder string, lookupEnv func(string) (string, bool)) string {
98 parts := strings.Split(varExpr, ":")
99 if len(parts) == 1 {
100 switch varExpr {
101 case "localWorkspaceFolder", "containerWorkspaceFolder":
102 return workspaceFolder
103 case "localWorkspaceFolderBasename", "containerWorkspaceFolderBasename":
104 return filepath.Base(workspaceFolder)
105 default:
106 val, ok := lookupEnv(varExpr)
107 if ok {
108 return val
109 }
110 return ""
111 }
112 }
113 switch parts[0] {
114 case "env", "localEnv", "containerEnv":
115 if val, ok := lookupEnv(parts[1]); ok {
116 return val
117 }
118 if len(parts) == 3 {
119 return parts[2]
120 }
121 }
122 return ""
123}
124
125// HasImage returns true if the devcontainer.json specifies an image.
126func (s Spec) HasImage() bool {

Callers 1

SubstituteVarsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected