@@ -32,16 +32,23 @@ type pkgMatch struct {
32
32
func expandPatterns (conf * LoadConfig , patterns ... string ) ([]* pkgMatch , error ) {
33
33
pkgMatches := []* pkgMatch {}
34
34
35
- addMatch := func (dir string , match string ) {
35
+ addPkgDir := func (dir string , match * string ) {
36
36
idx := slices .IndexFunc (pkgMatches , func (sum * pkgMatch ) bool { return sum .Dir == dir })
37
37
if idx == - 1 {
38
- pkgMatches = append (pkgMatches , & pkgMatch {Dir : dir , Match : []string {match }})
38
+ matches := []string {}
39
+ if match != nil {
40
+ matches = append (matches , * match )
41
+ }
42
+ pkgMatches = append (pkgMatches , & pkgMatch {Dir : dir , Match : matches })
43
+ return
44
+ }
45
+ if match == nil {
39
46
return
40
47
}
41
- if slices .Contains (pkgMatches [idx ].Match , match ) {
48
+ if slices .Contains (pkgMatches [idx ].Match , * match ) {
42
49
return
43
50
}
44
- pkgMatches [idx ].Match = append (pkgMatches [idx ].Match , match )
51
+ pkgMatches [idx ].Match = append (pkgMatches [idx ].Match , * match )
45
52
}
46
53
47
54
kinds := make ([]patternKind , 0 , len (patterns ))
@@ -54,31 +61,42 @@ func expandPatterns(conf *LoadConfig, patterns ...string) ([]*pkgMatch, error) {
54
61
}
55
62
56
63
if slices .Contains (kinds , patternKindSingleFile ) {
64
+ remaining := []string {}
65
+ remainingKinds := []patternKind {}
66
+
57
67
files := make ([]string , 0 , len (patterns ))
58
68
for i , match := range patterns {
59
69
kind := kinds [i ]
60
- if kind != patternKindSingleFile || ! strings .HasSuffix (match , ".gno" ) {
70
+ if kind != patternKindSingleFile {
71
+ remaining = append (remaining , match )
72
+ remainingKinds = append (remainingKinds , kind )
73
+ continue
74
+ }
75
+ if ! strings .HasSuffix (match , ".gno" ) {
61
76
return nil , fmt .Errorf ("named files must be .gno files: %s" , match )
62
77
}
63
78
files = append (files , match )
64
79
}
65
- return []* pkgMatch {{Dir : "command-line-arguments" , Match : files }}, nil
80
+
81
+ pkgMatches = append (pkgMatches , & pkgMatch {Dir : "command-line-arguments" , Match : files })
82
+
83
+ patterns = remaining
84
+ kinds = remainingKinds
66
85
}
67
86
68
87
for i , match := range patterns {
69
88
patKind := kinds [i ]
70
89
71
90
switch patKind {
72
- case patternKindSingleFile :
73
- return nil , fmt .Errorf ("%s: single file patterns are not supported" , match )
74
-
75
91
case patternKindRecursiveRemote :
76
92
return nil , fmt .Errorf ("%s: recursive remote patterns are not supported" , match )
77
93
78
94
case patternKindRemote :
79
95
if conf .SelfContained {
80
96
return nil , fmt .Errorf ("%s: remote patterns are not supported in self-contained mode" , match )
81
97
}
98
+ case patternKindSingleFile :
99
+ return nil , fmt .Errorf ("unexpected single pattern at this point" )
82
100
}
83
101
84
102
pat , err := cleanPattern (match , patKind )
@@ -88,22 +106,25 @@ func expandPatterns(conf *LoadConfig, patterns ...string) ([]*pkgMatch, error) {
88
106
89
107
switch patKind {
90
108
case patternKindDirectory :
91
- addMatch (pat , match )
109
+ addPkgDir (pat , & match )
92
110
93
111
case patternKindRemote :
94
112
dir := gnomod .PackageDir ("" , module.Version {Path : pat })
95
113
if err := downloadPackage (conf , pat , dir ); err != nil {
96
114
return nil , err
97
115
}
98
- addMatch (dir , match )
116
+ addPkgDir (dir , & match )
99
117
100
118
case patternKindRecursiveLocal :
101
119
dirs , err := expandRecursive (pat )
102
120
if err != nil {
103
121
return nil , fmt .Errorf ("%s: %w" , pat , err )
104
122
}
123
+ if len (dirs ) == 0 {
124
+ conf .IO .ErrPrintfln (`gno: warning: %q matched no packages` , match )
125
+ }
105
126
for _ , dir := range dirs {
106
- addMatch (dir , match )
127
+ addPkgDir (dir , & match )
107
128
}
108
129
}
109
130
}
@@ -158,7 +179,7 @@ const (
158
179
)
159
180
160
181
func getPatternKind (pat string ) (patternKind , error ) {
161
- isLitteral := patternIsLiteral (pat )
182
+ isLitteral := PatternIsLiteral (pat )
162
183
163
184
if patternIsRemote (pat ) {
164
185
if isLitteral {
0 commit comments