MCPcopy Create free account
hub / github.com/dim-an/cod / CompileSelector

Function CompileSelector

util/selector.go:28–72  ·  view source on GitHub ↗
(glob, homeDir string)

Source from the content-addressed store, hash-verified

26}
27
28func CompileSelector(glob, homeDir string) (g Selector, err error) {
29 if strings.HasPrefix(glob, "~/") {
30 if len(homeDir) == 0 {
31 err = fmt.Errorf("cannot expand %q pattern, home directory is unknown", homeDir)
32 return
33 }
34 glob = filepath.Join(homeDir, strings.TrimPrefix(glob, "~/"))
35 }
36
37 dir, name := filepath.Split(glob)
38
39 check := func(s string) error {
40 if strings.IndexRune(s, '*') != -1 {
41 return fmt.Errorf("bad glob: '*' and '**' are supported only as last component of the path")
42 }
43 return nil
44 }
45
46 if name == "*" {
47 err = check(dir)
48 if err != nil {
49 return
50 }
51 g = starGlob(dir)
52 } else if name == "**" {
53 err = check(dir)
54 if err != nil {
55 return
56 }
57 g = starStarGlob(dir)
58 } else if strings.ContainsRune(glob, os.PathSeparator) {
59 err = check(glob)
60 if err != nil {
61 return
62 }
63 g = noStarGlob(glob)
64 } else {
65 err = check(glob)
66 if err != nil {
67 return
68 }
69 g = baseNameGlob(glob)
70 }
71 return
72}
73
74type baseNameGlob string
75

Callers 3

handleListCommandsMethod · 0.92
initRuleFunction · 0.92
TestGlobExpression_MatchFunction · 0.85

Calls 4

starGlobTypeAlias · 0.85
starStarGlobTypeAlias · 0.85
noStarGlobTypeAlias · 0.85
baseNameGlobTypeAlias · 0.85

Tested by 1

TestGlobExpression_MatchFunction · 0.68