MCPcopy Create free account
hub / github.com/compose-spec/compose-go / WithDefaultConfigPath

Function WithDefaultConfigPath

cli/options.go:155–190  ·  view source on GitHub ↗

WithDefaultConfigPath searches for default config files from working directory

(o *ProjectOptions)

Source from the content-addressed store, hash-verified

153
154// WithDefaultConfigPath searches for default config files from working directory
155func WithDefaultConfigPath(o *ProjectOptions) error {
156 if len(o.ConfigPaths) > 0 {
157 return nil
158 }
159 pwd, err := o.GetWorkingDir()
160 if err != nil {
161 return err
162 }
163 for {
164 candidates := findFiles(DefaultFileNames, pwd)
165 if len(candidates) > 0 {
166 winner := candidates[0]
167 if len(candidates) > 1 {
168 logrus.Warnf("Found multiple config files with supported names: %s", strings.Join(candidates, ", "))
169 logrus.Warnf("Using %s", winner)
170 }
171 o.ConfigPaths = append(o.ConfigPaths, winner)
172
173 overrides := findFiles(DefaultOverrideFileNames, pwd)
174 if len(overrides) > 0 {
175 if len(overrides) > 1 {
176 logrus.Warnf("Found multiple override files with supported names: %s", strings.Join(overrides, ", "))
177 logrus.Warnf("Using %s", overrides[0])
178 }
179 o.ConfigPaths = append(o.ConfigPaths, overrides[0])
180 }
181 return nil
182 }
183 parent := filepath.Dir(pwd)
184 if parent == pwd {
185 // no config file found, but that's not a blocker if caller only needs project name
186 return nil
187 }
188 pwd = parent
189 }
190}
191
192// WithEnv defines a key=value set of variables used for compose file interpolation
193func WithEnv(env []string) ProjectOptionsFn {

Callers

nothing calls this directly

Calls 3

findFilesFunction · 0.85
GetWorkingDirMethod · 0.80
DirMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…