MCPcopy
hub / github.com/dagger/dagger / parseModRef

Method parseModRef

cmd/dagger/shell_fs.go:275–317  ·  view source on GitHub ↗

parseModRef transforms user input into a full module reference that can be used with dag.ModuleSource().

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

273// parseModRef transforms user input into a full module reference that can be used with
274// dag.ModuleSource().
275func (h *shellCallHandler) parseModRef(ctx context.Context, path string) (rcfg *configuredModule, rerr error) {
276 if h.Debug() {
277 shellDebug(ctx, "parseModRef (before)", path)
278
279 defer func() {
280 shellDebug(ctx, "parseModRef (after)", path, rcfg)
281 }()
282 }
283
284 h.mu.RLock()
285 context := h.wd.Context
286 h.mu.RUnlock()
287
288 // If no module loaded, let API handle it
289 if context == nil {
290 return h.getModuleConfig(ctx, path)
291 }
292
293 // Let's see if it's a relative path within the current context first
294 apath, err := h.contextAbsPath(path)
295 if err != nil {
296 return nil, err
297 }
298 ref := context.ModRef(apath)
299
300 if _, ok := context.(localSourceContext); ok {
301 // For local sources, there's no sense in requesting the API
302 // if the resolved ref doesn't exist
303 if _, err := os.Stat(ref); err != nil {
304 ref = ""
305 }
306 }
307
308 // best effort for use case of user providing a path within the current context
309 if ref != "" {
310 if cfg, _ := h.getModuleConfig(ctx, ref); cfg != nil {
311 return cfg, nil
312 }
313 }
314
315 // fallback to original path, which may be an absolute ref
316 return h.getModuleConfig(ctx, path)
317}
318
319type configuredModule struct {
320 Source *dagger.ModuleSource

Callers 1

maybeLoadModuleMethod · 0.95

Calls 6

DebugMethod · 0.95
getModuleConfigMethod · 0.95
contextAbsPathMethod · 0.95
shellDebugFunction · 0.85
ModRefMethod · 0.65
StatMethod · 0.65

Tested by

no test coverage detected