MCPcopy Index your code
hub / github.com/dagger/dagger / FastModuleSourceKindCheck

Function FastModuleSourceKindCheck

core/modulerefs.go:23–48  ·  view source on GitHub ↗

FastModuleSourceKindCheck performs a quick heuristic check to determine whether a module ref string refers to a local path or a git source. Returns "" if the kind cannot be determined without further inspection.

(
	refString string,
	refPin string,
)

Source from the content-addressed store, hash-verified

21// whether a module ref string refers to a local path or a git source.
22// Returns "" if the kind cannot be determined without further inspection.
23func FastModuleSourceKindCheck(
24 refString string,
25 refPin string,
26) ModuleSourceKind {
27 switch {
28 case refPin != "":
29 return ModuleSourceKindGit
30 case len(refString) > 0 && (refString[0] == '/' || refString[0] == '.'):
31 return ModuleSourceKindLocal
32 case len(refString) > 1 && refString[0:2] == "..":
33 return ModuleSourceKindLocal
34 case strings.HasPrefix(refString, SchemeHTTP.Prefix()):
35 return ModuleSourceKindGit
36 case strings.HasPrefix(refString, SchemeHTTPS.Prefix()):
37 return ModuleSourceKindGit
38 case strings.HasPrefix(refString, SchemeSSH.Prefix()):
39 return ModuleSourceKindGit
40 case !strings.Contains(refString, "."):
41 // technically host names can not have any dot, but we can save a lot of work
42 // by assuming a dot-free ref string is a local path. Users can prefix
43 // args with a scheme:// to disambiguate these obscure corner cases.
44 return ModuleSourceKindLocal
45 default:
46 return ""
47 }
48}
49
50type ParsedRefString struct {
51 Kind ModuleSourceKind

Callers 2

pendingLegacyModuleFunction · 0.92
ParseRefStringFunction · 0.85

Calls 2

PrefixMethod · 0.80
ContainsMethod · 0.65

Tested by

no test coverage detected